Reputation: 491
Im using appcompat v7 for rendering the action bar on my Android project. This works very well on versions 4.x but the options menu (only the options menu) is not exibithed on 2.x.x versions. What is the problem?
My list_team.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_profile"
android:title="@string/menu_label_profile"
android:orderInCategory="100"
android:showAsAction="never"
app:showAsAction="never"/>
<item
android:id="@+id/action_about"
android:title="@string/menu_label_about"
android:orderInCategory="100"
android:showAsAction="always"
app:showAsAction="always"/>
My Activity
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_team);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.list_team, menu);
return true;
}
}
Appreciate any help.
Upvotes: 1
Views: 751
Reputation: 55340
Devices with Android 2.X usually have a hardware menu button. In that case the overflow menu icon is not displayed (at least by default, not sure if there is a toggle for this in appcompat, though there was in ActionBarSherlock).
Nevertheless, tthe options should be accessible when pressing the menu button. May that be the case?
Upvotes: 1
Reputation: 13616
Based on this code, you are missing super.onCreateOptionsMenu()
in your override:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.list_team, menu);
return super.onCreateOptionsMenu(menu);
}
And you should also only use app:showAsAction
namespace as has been previously suggested.
Upvotes: 1
Reputation: 11978
Try to delete these two attributes android:showAsAction=""
and keeping only these app:showAsAction=""
instead.
According to the Google Documentation:
If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace.
You can also change the orderInCategory
of *action_about* to 1.
Upvotes: 1