8 Replies - 175 Views - Last Post: 06 March 2019 - 04:31 PM

#1 [email protected]   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 161
  • Joined: 24-February 15

how to fit logo inside action

Posted 06 March 2019 - 06:47 AM

So I tried two ways to put a logo inside my action bar, 1 through XML and 1 through java code.
The only thing is with XML it doesn't fit inside the action bar and with the code, it fits but it is centered.

photo: https://imgur.com/V4pFYds

I searched how to do it with code to align it the right but I get an error.

java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any"). See TransactionGuard documentation for details.
  current modality=ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog0,599,422,722x195,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Application Installation Failed,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog$DialogRootPane[,8,31,706x156,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=449,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]]}
  known modalities:
    ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog1,210,203,640x493,invalid,hidden,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Select Deployment Target,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=,rootPaneCheckingEnabled=true]]}, writingAllowed=true;
    ModalityState.NON_MODAL, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{}, writingAllowed=true;
    ModalityState:{[com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog[dialog0,599,422,722x195,layout=java.awt.BorderLayout,APPLICATION_MODAL,title=Application Installation Failed,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog$DialogRootPane[,8,31,706x156,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=449,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]]}, writingAllowed=false
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:126)
	at com.intellij.openapi.application.TransactionGuardImpl.assertWriteSafeContext(TransactionGuardImpl.java:251)
	at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeProjectChangeAction(ExternalSystemApiUtil.java:471)
	at com.android.tools.idea.project.IndexingSuspender.lambda$startBatchUpdate$1(IndexingSuspender.java:315)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$pollQueueLater$0(TransactionGuardImpl.java:74)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
	at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:817)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:758)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:394)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:109)
	at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
	at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
	at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
	at java.awt.Dialog.show(Dialog.java:1077)
	at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog.show(DialogWrapperPeerImpl.java:698)
	at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.show(DialogWrapperPeerImpl.java:430)
	at com.intellij.openapi.ui.DialogWrapper.invokeShow(DialogWrapper.java:1690)
	at com.intellij.openapi.ui.DialogWrapper.show(DialogWrapper.java:1639)
	at com.intellij.openapi.ui.messages.MessageDialog.show(MessageDialog.java:181)
	at com.intellij.ui.messages.MessagesServiceImpl.showMessageDialog(MessagesServiceImpl.java:63)
	at com.intellij.openapi.ui.Messages.showDialog(Messages.java:204)
	at com.intellij.openapi.ui.Messages.showOkCancelDialog(Messages.java:616)
	at com.intellij.openapi.ui.Messages.showOkCancelDialog(Messages.java:629)
	at com.intellij.openapi.ui.Messages.showOkCancelDialog(Messages.java:640)
	at com.android.tools.idea.run.RetryingInstaller$UserPrompter.lambda$showQuestionPrompt$0(RetryingInstaller.java:176)
	at com.intellij.util.ui.UIUtil$14.run(UIUtil.java:3144)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:817)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:758)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:394)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)



Java code
toolbar.setLogo(R.drawable.djosink_logo);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)toolbar.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);




XML

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"

                android:src="@drawable/djosink_logo" />

        </RelativeLayout>

    </android.support.design.widget.AppBarLayout>


This post has been edited by [email protected]: 06 March 2019 - 06:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to fit logo inside action

#2 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 10:36 AM

toolbar.setLogo(R.drawable.djosink_logo);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)toolbar.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);



Shouldn't you be applying ALIGN_PARENT_RIGHT to the ImageView instead of the RelativeLayout ??? Relative layout doesn't respond to that attribute. It can only be applied to UI elements that are within the relative layout.

Instantiate your ImageView then apply it the same way you did in your code example.
Was This Post Helpful? 0
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 10:50 AM

[email protected]This is Java and I'm in Xamarin (C#) so I can't test it but try:

//_myViewInflater = your view

ImageView imageView = (ImageView)_myViewInflater.FindViewById<ImageView>(R.Id.logo);

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)toolbar.getLayoutParams();

imageView.setLayoutParams(params);



You will need to assign the ImageView upon instantiation (can't use this abstract AFAIK)
Was This Post Helpful? 0
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 11:16 AM

Nvm... that won't work either I don't think because we're still trying to apply the ALIGN_PARENT_RIGHT to RelativeLayout .. I'll have to look into it more. Disregard that
Was This Post Helpful? 0
  • +
  • -

#5 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 11:35 AM

OK so I was wrong... you can apply the attribute to your LayoutParameters like you were doing.

//_myViewInflater = your view

ImageView imageView = (ImageView)_myViewInflater.FindViewById<ImageView>(R.Id.logo);

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)toolbar.getLayoutParams();

params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);

imageView.setLayoutParams(params);




I'll look into that exception...I'm not sure why the ALIGN_PARENT_RIGHT wouldn't work inside the ActionBar

I think even if we can assign that attribute programmatically it won't matter because assigning that way is basically the same as assigning through the XML.
Was This Post Helpful? 0
  • +
  • -

#6 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 12:04 PM

So this works via XML in Xamarin. I wouldn't even mess around with doing it programmatically.

... you could try changing your layout_width temporarily to an int and then back to wrap_content ... I was having an issue briefly where it didn't work until I did that for some reason, but it was probably an IDE glitch so may not be applicable for AS.

android:layout_alignParentRight="true"

Attached Image

Removed

Attached Image
Was This Post Helpful? 0
  • +
  • -

#7 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 12:19 PM

You know you can use

			android:layout_width="60"
			android:layout_height="60"
                        android:maxHeight="66dp"
                        android:maxWidth="66dp"



to set the size of your image? (obviously would need to be tweaked)

and have you tried changing those values in the relative layout? IF it's already partially working with XML versus programmatically this will probably be easier to just make adjustments.

This post has been edited by hexagod: 06 March 2019 - 12:20 PM

Was This Post Helpful? 0
  • +
  • -

#8 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 12:36 PM

One last thing, that error you are getting has nothing to do with the alignment issue. It looks like it's either a bug or related to file save status, write permissions, repo. If you have more than one project open try closing them. Make sure your IDE is up to date. So basically make sure your IDE is healthy, maybe then try copying your project into a new directory? I'm out... sorry for the spam I had your problems reversed. Probably disregard most of it and just try to get the IDE working.
Was This Post Helpful? 0
  • +
  • -

#9 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: how to fit logo inside action

Posted 06 March 2019 - 04:31 PM

I don't mean to blow up your thread but also just found this while working on my own project, not sure if it would help you.

android:scaleType="fitEnd"
android:scaleType="fitStart"

Can use it to control the scaling type of an ImageView .. maybe try it on the XML example where the image doesn't fit on the bar?

EDIT: http://etcodehome.bl...pe-samples.html

This post has been edited by hexagod: 06 March 2019 - 04:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1