Action Bar items not Showing

2019-09-09 07:47发布

问题:

I have inflated my action bar and created items. They show in the overflow but when I try to add code and make them show with yourapp:showAsAction="ifRoom", it gives me errors.

Here is my main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item android:id="@+id/home"
      android:icon="@drawable/ic_menu_home"
      android:title="Home"
      yourapp:showAsAction="ifRoom" />
<item android:id="@+id/back"
      android:icon="@drawable/ic_menu_back"
      android:title="Back"
      yourapp:showAsAction="ifRoom"  />

</menu>

Here is my java code:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

Thank you in advance!

回答1:

change

 yourapp:showAsAction="ifRoom"

to

android:showAsAction="ifRoom"