I'm developing an application in which I have to put drawables on top of the actionbar and have to update then from time to time. Here is a layout what I want it to look like.
I want to put a drawable as shown in the picture atttached(The green color drawable not the notification thing). Is that possible to achieve this kind of screen in android? If, so please guide me how to achieve this.
Any kind of help will be appreciated.
This is easy using a custom view. Let me explain you the steps briefly:
Create your custom view in the layout folder. For example, an ImageButton
.
Set this view as the custom view of the action bar in your activity. You can do this by calling
getSupportActionBar().setCustomView(R.layout.your_custom_view);
(or getActionBar()
instead of getSupportActionBar()
)
Call setDisplayOptions()
with the ActionBar.DISPLAY_SHOW_HOME
and ActionBar.DISPLAY_SHOW_CUSTOM
options.
If you have other standard buttons in the action bar, inflate the menu.
You can finally set the OnClickListener
for your custom view.
This worked for me, hope it helps you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With