actionlayout on menuitem does nothing

痞子三分冷 提交于 2019-11-27 07:22:22
Ben Harris

Try app:actionLayout="@layout/check" instead of android:actionLayout="@layout/check".

If you're using ActionbarSherlock or AppCompat, the android: namespace will not work for MenuItems. This is because these libraries use custom attributes that mimic the Android APIs since they did not exist in earlier versions of the framework.

when using Appcompact ,menu item will be like

<item android:id="@+id/cart"
    app:actionLayout="@layout/actionbar_cart"
    android:title="@string/action_cart"
    app:showAsAction="always"
 />

The answer from Ben Harris is absolutely correct. However, in some case like when using attributes like:

      app:showAsAction="ifRoom|collapseActionView"

used in SearchView (in my case), the layout view isn't shown and that caused a lot of headache to me. It seems that collapseActionView is not supported with action view in appcombat. So consider this as well while doing your stuffs.

use app namespace instead of android and it will work fine.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/action_submit"
        app:actionLayout="@layout/check"
        app:showAsAction="always"  />
</menu>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!