Define action bar overflow elements

If I define the following elements for my action bar:

res/menu/action_menu.xml :

 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="label"/> <item android:title="label1"/> <item android:title="label2"/> <item android:title="label3"/> <item android:title="label4"/> </menu> 

In my activity:

 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.action_menu, menu); return true; } 

In any case, to allow certain elements to move into the action overflow part ? and how to do it?

PS The action overflow part is the largest part of the action bar, which hides certain elements, such as a pop-up menu.

+6
source share
2 answers

This is the opposite. You need to explicitly specify the menu you want in the ActionBar , and not by setting the appropriate flags

eg.

 <item android:id="@+id/refresh" android:title="@string/refresh" android:icon="@drawable/reload_button" android:showAsAction="always"/> 

Here android:showAsAction tells how to handle it. Parameters

  • is always
  • ifRoom
  • never
  • withText

You can either parameters along with the pipe symbol as "always | withText"

For more information about the documents, see the android docs file for the action bar .

+10
source

To add something to Heiko’s answer about the “overflow menu” in the action bar, this only happens if you have items set to “Rum” and there is no place to display them. In the overflow menu, they appear only with a title and no icon.

In Android 4.0, the overflow menu (“3-point counter”) is displayed only on devices that do not have a physical “menu” button. You can check this on the ADV setup with the Hardware Back/Home keys option to "no."

+8
source

Source: https://habr.com/ru/post/908420/


All Articles