Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define Action bar overflow items

If I define the following items 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;
}

Is there anyway to allow me define certain items move to action overflow part ? and how to do it?

P.S. Action overflow part is the right-most part of action bar which hide certain items like a popup menu.

like image 543
Mellon Avatar asked Feb 14 '12 10:02

Mellon


1 Answers

It's the other way round. You need to explicitly tell the menu which ones you want in the ActionBar and which not by setting the appropriate flags

E.g.

<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. Options are

  • always
  • ifRoom
  • never
  • withText

You can or options together with the pipe symbol as "always|withText"

See the android docs for action bar for more documentation.

like image 87
Heiko Rupp Avatar answered Sep 29 '22 05:09

Heiko Rupp