actionLayout 不显示在导航抽屉中

actionLayout not show in navigation drawer

我在使用自定义布局作为导航抽屉中的菜单项时遇到了一些问题。当我使用 app:actionLayout 时,只显示一个标题。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/drawer_menu_header"
        app:itemIconTint="@color/colorGray"
        app:itemTextColor="@color/colorGray"
        app:menu="@menu/drawer_menu">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

drawer_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:showIn="navigation_view">

    <group android:id="@+id/menu_grp1" android:checkableBehavior="single">
        <item
            android:id="@+id/menu_add_event"
            android:icon="@drawable/menu_add"
            android:title="@string/menu_add_event"/>
        <item
            android:id="@+id/menu_add_service"
            android:icon="@drawable/menu_add"
            android:title="@string/menu_add_service"/>
    </group>

    <group android:id="@+id/menu_grp2" android:checkableBehavior="single">
        <item
            android:id="@+id/menu_home"
            android:icon="@drawable/menu_home"
            android:title="@string/menu_home"/>
        <item
            android:id="@+id/menu_event"
            android:icon="@drawable/menu_event"
            android:title="@string/menu_event"/>
        <item
            android:id="@+id/menu_interesting"
            android:icon="@drawable/menu_interesting"
            android:title="@string/menu_interesting"/>
        <item
            android:id="@+id/menu_service"
            android:icon="@drawable/menu_service"
            android:title="@string/menu_service"/>
        <item
            android:id="@+id/menu_about"
            android:icon="@drawable/menu_about"
            android:title="@string/menu_about" />
        <item
            android:id="@+id/menu_advertising"
            android:icon="@drawable/menu_advertising"
            android:title="@string/menu_advertising" />
    </group>

    <group android:id="@+id/menu_grp3" android:checkableBehavior="single">

        <item
            android:id="@+id/menu_news"
            android:icon="@drawable/menu_news"
            android:title="@string/menu_news"/>
        <item
            android:id="@+id/menu_favorite"
            android:icon="@drawable/menu_favorite"
            android:title="@string/menu_favorite" />
        <item
            android:id="@+id/menu_visited"
            android:icon="@drawable/menu_visited"
            android:title="@string/menu_visited" />
        <item
            android:id="@+id/menu_logout"
            android:icon="@drawable/menu_logout"
            android:title="@string/menu_logout" />
    </group>

    <group android:id="@+id/menu_grp4" android:checkableBehavior="single">
        <item
            android:id="@+id/menu_social"
            android:title="title"
            app:actionLayout="@layout/drawer_menu_footer"
            app:showAsAction="always"
            android:visible="true"/>
    </group>
</menu>

drawer_menu_footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/menu_facebook"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/menu_social_buttons_margin"
        app:srcCompat="@drawable/menu_facebook" />

    <ImageView
        android:id="@+id/menu_instagram"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/menu_social_buttons_margin"
        app:srcCompat="@drawable/menu_instagram" />

    <ImageView
        android:id="@+id/menu_p"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/menu_pinterest" />
</LinearLayout>

我通过在 drawer_menu_footer.xml

中用 android:background 替换 app:srcCompat 解决了我的问题