Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarCompat shows every action in the overflow menu

I've started using the ActionBar coming with the AppCompat library. But any action I add to this, shows up in the overflow menu. I'm pretty sure I've skipped something, but I don't know at all. Here's my menu file:

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

    <item
        android:id="@+id/connect_plus"
        android:icon="@drawable/ic_google_plus"
        android:title="Connect to Google+"
        android:showAsAction="always"
        android:titleCondensed="Connect to Google+">
    </item>

</menu>

And any configuration in the onCreate method from an activity extending from ActionBarActivity:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Did I miss something?

like image 266
Sergi Juanola Avatar asked Aug 05 '13 21:08

Sergi Juanola


1 Answers

Did I miss something?

Yes.

You need to use your own namespace:

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

    <item
        android:id="@+id/connect_plus"
        android:icon="@drawable/ic_google_plus"
        android:title="Connect to Google+"
        yourapp:showAsAction="always"
        android:titleCondensed="Connect to Google+">
    </item>

</menu>

as is shown in the documentation.

like image 65
CommonsWare Avatar answered Jan 14 '23 18:01

CommonsWare