I'm following the google tutorial for action bars but the icons don't appear on it, this is the menu xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_refresh"
android:icon="@drawable/ic_action_refresh"
android:title="refresh"
android:showAsAction="ifRoom"/>
<item android:id="@+id/action_settings"
android:icon="@drawable/ic_action_settings"
android:title="settings"
android:showAsAction="ifRoom"/>
<item android:id="@+id/action_compose"
android:icon="@drawable/ic_action_new"
android:title="add"
android:showAsAction="ifRoom"/>
</menu>
and this in my main acivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_bar, menu);
return super.onCreateOptionsMenu(menu);
}
Use yourapp:showAsAction
instead of android:showAsAction
And make sure your Activity
extends ActionBarActivity
from the compat lib
来源:https://stackoverflow.com/questions/25625239/android-icons-dont-appear-in-action-bar