Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action Bar not displaying Action Items (All in overflow) Android

I can't get the Action Bar to display my action items. They all show up in the overflow menu. I have pasted all the relevant code below. Can anyone see my problem?

From Activity:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater mi = getMenuInflater();
    mi.inflate(R.menu.viewer_menu, menu);
    return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {

    case R.id.menu_download:
        return true;
    case R.id.menu_star:
        return true;
    case R.id.menu_report:
        return true;
        case android.R.id.home:
        // app icon in action bar clicked; go home
            finish();
            return true;
    }
    return false;
}

From Manifest:

<activity android:name=".CustomActivity"

     android:label="">

From values-v11 folder (themes.xml)

<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo">
</style>

from menu folder (viewer_menu.xml)

<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_download"
    android:title="Download" showAsAction="withText"
    android:orderInCategory="2"/>
<item android:id="@+id/menu_star"
    android:icon="@android:drawable/ic_menu_upload"
    android:title="Star"
     showAsAction="always"
    android:orderInCategory="1"/>
    <item android:id="@+id/menu_report"
    android:title="Report Problem" showAsAction="always"
    android:orderInCategory="0"/>
</menu>
like image 565
easycheese Avatar asked Mar 31 '12 19:03

easycheese


2 Answers

It is android:showAsAction, not just showAsAction.

like image 146
CommonsWare Avatar answered Oct 05 '22 22:10

CommonsWare


If you are using support package (android.support.v7.app.ActionBarActivity), you have to use something like this:

<menu
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <item android:id="@+id/menu_download"
      android:title="Download" 
      app:showAsAction="withText"
      android:orderInCategory="2"/>

  <item android:id="@+id/menu_star"
      android:icon="@android:drawable/ic_menu_upload"
      android:title="Star"
      app:showAsAction="always"
      android:orderInCategory="1"/>

  <item android:id="@+id/menu_report"
      android:title="Report Problem" 
      app:showAsAction="always"
      android:orderInCategory="0"/>
</menu>
like image 34
gingo Avatar answered Oct 05 '22 23:10

gingo