Android actionLayout not showing with Toolbar

时光总嘲笑我的痴心妄想 提交于 2020-07-30 04:36:06

问题


I'm trying to show custom layout as an item in options menu. And this is what I have done so far

<item
    android:id="@+id/action_profile"
    android:orderInCategory="100"
    android:title="Profile"
    android:actionLayout="@layout/layout_menu_profile"
    app:showAsAction="never" />

I tried

    app:actionLayout="@layout/layout_menu_profile"

as well as per this SO link but still it shows only title - Profile

I have created new project through Android Studio 1.5 with Blank Activity. with minSDK = 15 and targetSDK = 23

Following is the code in Blank Activity.

@Override
 public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_home, menu);

    MenuItem item = menu.findItem(R.id.action_profile);


    return true;
}

where am I going wrong ?


回答1:


use app:actionLayout instead of android:actionLayout.

<item
   ...
   app:actionLayout="@layout/layout_menu_profile"  
   app:showAsAction="always" />



回答2:


Try this code

<item
android:id="@+id/action_profile"
android:orderInCategory="100"
android:title="Profile"
android:actionLayout="@layout/layout_menu_profile"
app:showAsAction="always" />

Just set the showAsAction elements to always



来源:https://stackoverflow.com/questions/35535374/android-actionlayout-not-showing-with-toolbar

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