This question already has an answer here:
- Actionbar not shown with AppCompat 3 answers
Here is my general.xml
file
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/next"
android:title="Next"
android:visible="true"
android:enabled="true"
android:showAsAction="always"
android:orderInCategory="1">
</item>
<item
android:id="@+id/Previous"
android:title="Previous"
android:visible="true"
android:enabled="true"
android:orderInCategory="2"
android:showAsAction="always">
</item>
<item android:id="@+id/star"
android:icon="@drawable/ic_action_important"
android:enabled="true"
android:orderInCategory="0"
android:showAsAction="always"
android:title="Star"
android:visible="true">
</item>
</menu>
Here is my code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.general, menu);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#003f84")));
return true;
}
Now, my problem is menu items isn't showing in actionbar. Am I doing anything wrong here?
showAsAction
should be in a different namespace (yourapp
in the sample below).youapp
is simply a namespace identifier that points to namespacehttp://schemas.android.com/apk/res-auto
, you can change it to anything. The SDK will automatically map that namespace to your package name (see changelog below).This is necessary so that it could properly find attributes that are not available in previous OS versions and instead are part of your application's package. Note from documentation: