Question

I have a simple question.

Is the following scenario possible with the Android Actionbar:

  • Actiobar Title
  • CustomView1
  • CustomView2
  • Normal MenuItem

Graphical representation:

enter image description here

What I know is that it's possible to have a custom Actionbar View by using this method:

ActionBar.setCustomView(View v);

in addition to that, I know having a title and normal MenuItems in combination with a CustomView is supported as well.

But is it possible to have multiple custom Views (like in the picture above) in the ActionBar, and if yes, how?

Was it helpful?

Solution

Just create custom layout for your ActionBar menu items and find the menu items to which you want to provide custom layout in onCreateOptionsMenu and call setActionView(View view) on them.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    ...
    MenuItem item = menu.findItem(R.id.YOUR_MENU_ITEM_ID);
    item.setActionView(R.layout.YOUR_CUSTOM_LAYOUT);     
    ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top