質問

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?

役に立ちましたか?

解決

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);     
    ...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top