自定义 actionLayout 未显示在 NavDrawer 项目中

Custom actionLayout not showing in NavDrawer item

我在为导航抽屉中的菜单项使用自定义视图时遇到了一些问题。当我使用 android:actionLayout 时,尽管布局有效,但没有任何变化。显示项目文本,但未显示自定义布局中的任何内容。根据我在文档中阅读的内容,我不需要任何 java 代码,并且应该能够纯粹在 xml 中设置它,对吗?

我的activity抽屉和actionLayoutxml文件如下:

activity_main_drawer.xml 文件:

<group android:checkableBehavior="none" >
    <item ... />
    <item ... />
    <item ... />
</group>

<group android:id="@+id/menu_bottom" android:checkableBehavior="none">
    <item ... />
</group>

<group android:id="@+id/bookmark_list" android:checkableBehavior="single">
    <item
        android:id="@+id/nav_bookmark"
        android:actionLayout="@layout/nav_bookmark_header_layout"
        android:title="Some text"
        app:showAsAction="ifRoom" />
</group>

layout/nav_bookmark_header_layout.xml 文件:

<TextView
    android:id="@+id/counterView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Custom text"/>

啊,找到了。 android:actionLayout 应该是 app:actionLayout

用作动作视图的布局。 app:actionLayout 你应该使用它在 API 级别 11 中介绍。