How do I change Item title font color for an Item that contains a menu in Navigation Drawer

匆匆过客 提交于 2019-11-28 09:48:39

问题


I've been searching for a way to change a specific font color in my nav drawer. I can change the font colors for other item titles but not ones containing a menu.

<group
    android:id="something"
    android:checkableBehavior="single>
    <item
        android:title="Menu Heading>   <--This is what I want to change-->
        <menu>
            <item android:title="stuff"/> <--This i can change-->
            <item android:title="stuff"/>
        </menu>
    </item>
</group>    

I can change all other title colors with app:itemTextColor in the main activity. I've tried changing my theme's alternate font color. I'm still relatively new to programming in general, so I'm assuming I'm missing something. The only thing i can think of is to use action layout and just inflate a custom layout in the items, but I'd prefer to not redo all of my onClicks. As it is my designer wants dark menu and the text is defaulted to black regardless of theme changes so far.


回答1:


Using app:itemTextColor, the menu item title color can be set. You can refer following xml code.

<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:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/your_menuitem_icon_color"
    app:itemTextColor="@color/your_menuitem_title_color"
    app:menu="@menu/menu" />



回答2:


To change the menu title instead of the individual item titles I just used html tags in the strings resource for color The title and referenced the strings xml as the title. This can be done for doing individual colors for each item also.

<string name="testTitle"><font color="#303F9F">The title</font></string>

<group
android:id="something"
android:checkableBehavior="single>
<item
    android:title="@string/testTitle">   <--This is what I want to change-->
    <menu>
        <item android:title="stuff"/> <--This i can change-->
        <item android:title="stuff"/>
    </menu>
</item>

I also noticed that this doesn't work if you have secondary text color in set in your styles.



来源:https://stackoverflow.com/questions/38132260/how-do-i-change-item-title-font-color-for-an-item-that-contains-a-menu-in-naviga

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!