Android actionLayout未与工具栏一起显示
问题描述:
我正在尝试将自定义布局显示为选项菜单中的一项. 这是我到目前为止所做的
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" />
我尝试了
app:actionLayout="@layout/layout_menu_profile"
以及此 SO链接,但仍仅显示标题-个人资料
as well as per this SO link but still it shows only title - Profile
我通过具有空白活动的Android Studio 1.5创建了新项目. minSDK = 15,targetSDK = 23
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;
}
我要去哪里错了?
答
使用app:actionLayout
代替android:actionLayout
.
<item
...
app:actionLayout="@layout/layout_menu_profile"
app:showAsAction="always" />