Android actionLayout未显示工具栏

Nay*_*pte 9 android menu android-optionsmenu android-toolbar

我正在尝试将自定义布局显示为选项菜单中的项目.这就是我到目前为止所做的

<item
    android:id="@+id/action_profile"
    android:orderInCategory="100"
    android:title="Profile"
    android:actionLayout="@layout/layout_menu_profile"
    app:showAsAction="never" />
Run Code Online (Sandbox Code Playgroud)

我试过了

    app:actionLayout="@layout/layout_menu_profile"
Run Code Online (Sandbox Code Playgroud)

以及每 SO链接,但它仍然只显示标题-简介

我通过Android Studio 1.5使用Blank Activity创建了新项目.minSDK = 15,targetSDK = 23

以下是空白活动中的代码.

@Override
 public boolean onCreateOptionsMenu(Menu menu) {

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

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


    return true;
}
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

小智 23

使用app:actionLayout而不是android:actionLayout.

完整代码......

<item
android:id="@+id/action_profile"
android:orderInCategory="100"
android:title="Profile"
app:actionLayout="@layout/layout_menu_profile"  
app:showAsAction="always" />
Run Code Online (Sandbox Code Playgroud)


小智 2

试试这个代码

<item
android:id="@+id/action_profile"
android:orderInCategory="100"
android:title="Profile"
android:actionLayout="@layout/layout_menu_profile"
app:showAsAction="always" />
Run Code Online (Sandbox Code Playgroud)

只需将showAsAction元素设置为始终