How to set drawables on actionbar of my android application - android

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!

Create custom view
Use it as ActionView in ActionBar
In onCreateOptionsMenu get a reference to your view and update it when needed

Related

Android ActionBar Custom Design

I am a newbie in android programming, i have to design an activity exactly like the picture in the link. I am extremely confused about how to add that search view under my actionbar.
you need ToolBar .find some example and you can modify its layout because its just a ViewGroup. Then use it as ActionBar.
You have to make a custom action bar, below will can help you to make it.
How can I implement custom Action Bar with custom buttons in Android?
then, you have to use text watcher(http://www.learn2crack.com/2014/02/android-textwatcher-example.html) in search textbox and use these methods acc. to your need:
1. afterTextChanged
2. beforeTextChanged
3. onTextChanged

How to position the elements in a custom action bar layout in Android?

I need to develop a custom layout for the action bar in Android.
I'm now stuck because I have no clue how to calculate the available space for my custom layout.
In the image, the red part is my custom layout, the blue part is the space occupied by the action buttons.
Clearly I need to know/calculate the size of the red part to be able to correctly position the elements in my custom action bar (for example center the title in the window or make sure not to overflow in the blue part).
How can I achieve this?
I couldn't find useful examples or a clear API in the Android documentation.
I think that anyone using the custom action bar layout must be facing this kind of problem, I'm a bit confused.
Or am I supposed not to use action buttons in this case? Perhaps I'm supposed to replicate the action buttons by myself?
Thanks in advance
Try using ToolBar instead of ActionBar. It will give you a lot more control over ActionBar elements than ActionBar.
Here is a simple tutorial about how to replace ActionBar with ToolBar and how you can customise it.
Material ToolBar
Possibilities are endless with ToolBar but my recommendation is to don't overdo anything.
As per my suggestion try to use the entire action bar by your custom layout. So that you can arrange all the things use it as a fragment inside a framelayout for all your screens so that the code can be reused for all your layouts.

Android Actionbar PopupMenu with Custom Item Layouts

I am working on an Android application where I have to design a menu which will populate from the action bar, like this:
I have tried my best but was not able to produce it using the Android controls.
The solutions I have tried are:
With Actionbar, add a menu item with a group with selectable="all", that produces the layout I need but when I click a checkbox for selecting it, the whole menu hides and selection is not done, moreover the menu icon in actionbar does not have the bottom right white arrow.
Tried creating a custom ActionProvider and added the menu items using class's OnPrepareSubMenu method but had the same issue.
I just need a push in the right direction and I can do the rest, suggestions are more than welcome.
Thank you :)
Use popupWindow.
In that you can make any custom layout and set it as content of your popupwindow and also you can specify an ANCHOR in your case it would be
R.id.your_menu_item
set a listener and listen the changes.

Android AppCompat ActionBar MenuItem view customization

Is there a way to change the appearance of action items inflated from menu.xml file? If so could you point me to the right direction. Thanks. If you need to know why do I need this, the main reason is that I dislike the default padding and the default selector
Well I figured this on my own.
To set custom MenuItem view use ActionProvided. In my case, I just extended ActionProvider class and overrode onCreateActionView method. What you'll do more, its up to you :)

Setting custom image view as action bar's menu icon

I would like to add one of the menu icons of the action bar as below.
I need an icon and a bubble on top of that and I need to display a number on that at run time.
Is it possible to do? I have Googled regarding this, but couldn't find exact way to do.
Thanks in advance.
what you want is call "badge"
A simple way to "badge" any given Android view at runtime without having to cater for it in layout.
try this Lib
https://github.com/jgilfelt/android-viewbadger
You will have to define custom layout for your action bar as mentioned in the tutorial here
and to display counter above the Imageview android notification class can be used.

Categories

Resources