actionLayout不显示在导航抽屉中

时间:2018-06-28 09:12:39

标签: android xml navigation-drawer menuitem

使用自定义布局作为导航抽屉中的菜单项时遇到一些麻烦。当我使用img_base_cvt = cv2.cvtColor(base_img_rgb,cv2.COLOR_BGR2GRAY) base_img = cv2.GaussianBlur =(img_base_cvt, (5,5), 0) # Use the SIFT feature detector detector = cv2.xfeatures2d.SIFT_create() # Find key points in base image for motion estimation base_features, base_descs = detector.detectAndCompute(base_img, None) 时,只会显示一个标题。

activity_main.xml

app:actionLayout

drawer_menu.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_footer.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>

1 个答案:

答案 0 :(得分:0)

我通过在 drawer_menu_footer.xml

中将app:srcCompat替换为android:background来解决了我的问题