Reputation: 957
I have an application, and need to add some buttons on the ActionBar. To add these buttons, I created a xml file called menu_action_bar. The code is:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item1"
android:title="Item 1"
android:showAsAction="always"/>
<item
android:id="@+id/item2"
android:icon="@drawable/icon"
android:title="Item 2"
android:showAsAction="ifRoom"/>
<item
android:id="@+id/item3"
android:title="Item 3"
android:showAsAction="never"/>
<item
android:id="@+id/item4"
android:title="Item 4"
android:showAsAction="never"/>
For this to have an effect in my application, I am rewriting the onCreateOptionsMenu method (Menu); The code was:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_action_bar, menu);
return true;
}
However, when starting my application, my action bar is the same way, without any alteration, as with the Icon and the application name. I tried changing the theme of the application to see if it had had any effect, but my project only lets me use the Theme.AppCompat.Light, may be the cause of the problem?
Upvotes: 0
Views: 46
Reputation: 1360
I answered a question similar to this about 1-2 months back. See this -> https://stackoverflow.com/a/22780579/2801779 and also see the comments below my answer. Your concepts about AppCompat
and v7
will be cleared. Look for HipHopDroid's (my) answer
Upvotes: 0
Reputation: 2792
try addign this to the menu tag:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >
and this to your items:
myapp:showAsAction="always"
Upvotes: 1