5

我无法更改子菜单标题的颜色,请参见下图。

我可以更改 NavigationView 的背景、字体颜色和图标颜色,但在子菜单标题上找不到答案。

例如

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/white"
    app:itemBackground="@color/white"
    app:itemIconTint="@color/dark_green"
    app:itemTextColor="@color/dark_green"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer" />

这是我的菜单xml:

<group android:checkableBehavior="single">
    <item
        android:checked="true"
        android:icon="@drawable/ic_attachment"
        android:title="@string/nav_item_attachment" />
    <item
        android:icon="@drawable/ic_image"
        android:title="@string/nav_item_images" />
    <item
        android:icon="@drawable/ic_place"
        android:title="@string/nav_item_location" />
</group>

<item android:title="@string/nav_sub_menu">
    <menu>
        <item
            android:icon="@drawable/ic_emoticon"
            android:title="@string/nav_sub_menu_item01" />
        <item
            android:icon="@drawable/ic_emoticon"
            android:title="@string/nav_sub_menu_item02" />
    </menu>
</item>

请指教。:-)。

NavigationView 子菜单问题

4

2 回答 2

2

尝试使用此代码执行如下图所示的操作

<menu>
    <group android:checkableBehavior="single">


        <item
            android:checked="true"
            android:icon="@drawable/ic_attachment"
            android:title="@string/nav_item_attachment" />
        <item
            android:icon="@drawable/ic_image"
            android:title="@string/nav_item_images" />
        <item
            android:icon="@drawable/ic_place"
            android:title="@string/nav_item_location" />
    </group>
    <group android:checkableBehavior="single">
       <item android:title="@string/nav_sub_menu">
        <menu>
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item01" />
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item02" />
        </menu>
      </item>
    </group>



</menu>

在此处输入图像描述

与您的代码的区别在于代码位于<group>...</group>

于 2015-11-10T16:47:23.837 回答
1

@乔治

像这样?

<group android:checkableBehavior="single">
    <item
        android:checked="true"
        android:icon="@drawable/ic_attachment"
        android:title="@string/nav_item_attachment" />
    <item
        android:icon="@drawable/ic_image"
        android:title="@string/nav_item_images" />
    <item
        android:icon="@drawable/ic_place"
        android:title="@string/nav_item_location" />
</group>

<group android:checkableBehavior="single">
    <item android:title="@string/nav_sub_menu">
        <menu>
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item01" />
            <item
                android:icon="@drawable/ic_emoticon"
                android:title="@string/nav_sub_menu_item02" />
        </menu>
    </item>
</group>

好像没什么区别

于 2015-11-10T17:20:39.747 回答