如何更改包含导航抽屉中菜单的项目的项目标题字体颜色 [英] How do I change Item title font color for an Item that contains a menu in Navigation Drawer

查看:127
本文介绍了如何更改包含导航抽屉中菜单的项目的项目标题字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来更改导航抽屉中的特定字体颜色.我可以更改其他项目标题的字体颜色,但不能更改包含菜单的项目的字体颜色.

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>    

我可以在主要活动中使用app:itemTextColor更改所有其他标题颜色.我尝试更改主题的备用字体颜色.总的来说,我对编程还是比较陌生的,所以我假设我错过了一些东西.我唯一能想到的就是使用操作布局,然后在项目中添加自定义布局,但是我宁愿不要重做所有的onClicks.因为这是我的设计师想要的深色菜单,并且到目前为止,无论主题如何更改,文本均默认为黑色.

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.

推荐答案

要更改菜单标题而不是单个项目标题,我只是在字符串资源中使用html标签作为颜色标题,并引用了字符串xml作为标题.也可以为每个项目分别设置颜色.

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.

这篇关于如何更改包含导航抽屉中菜单的项目的项目标题字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆