android.support.v7 with `ActionBarActivity` no menu shows

蓝咒 提交于 2019-11-28 04:52:44
CommonsWare

Try pressing the MENU button on your device or emulator, and see if they appear in the overflow.

If they do, then the problem is that your <menu> XML needs to change. Menu XML that works with ActionBarSherlock and the native API Level 11+ action bar will not work with the AppCompat action bar backport.

Your menu XML would need to look like this:

<?xml version="1.0" encoding="utf-8"?>
<menu
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:yourapp="http://schemas.android.com/apk/res-auto"
>
    <item android:id="@+id/item_menu_ok" android:icon="@drawable/ic_action_ok"
        android:title="@string/ok" yourapp:showAsAction="always"></item>
    <item android:id="@+id/item_menu_cancel" android:icon="@drawable/ic_action_cancel"
        android:title="@string/cancel" yourapp:showAsAction="always"></item>
</menu>

And you would need to use the same yourapp prefix for anything else related to the action bar (e.g., yourapp:actionLayout).

You can see this covered in the action bar documentation.

Maksim Dmitriev

I'd like to add a little to the answer.

If you want to see both text and an icon, please use withText in showAsAction I've just tested it; when I used always or ifRoom without withText, I only saw an icon.

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