Android: Icons don't appear in Action Bar

和自甴很熟 提交于 2020-01-13 17:57:11

问题


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);
    }

回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!