[英]How to change item text color from a NavigationDrawer menu using styles.xml?
I have a Styles.xml file describing the colors of my NavigationDrawer:我有一个 Styles.xml 文件描述了我的 NavigationDrawer 的颜色:
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item><!-- text size in menu-->
<item name="android:textColor">#880ACE0A</item>
</style>
I know that you should change this property of NavigationDrawer for the text colour: "app:itemTextColor", so I tried adding it to my styles.xml file:我知道您应该为文本颜色更改 NavigationDrawer 的此属性:“app:itemTextColor”,因此我尝试将其添加到我的 styles.xml 文件中:
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item><!-- text size in menu-->
<item name="android:textColor">#880ACE0A</item>
<item name="app:itemTextColor">#880ACE0A</item>
</style>
After adding it I have this compilation error on the file styles.xml:添加它后,我在文件 style.xml 上有这个编译错误:
Error:(12, 5) No resource found that matches the given name: attr 'app:itemTextColor'.
How to set the colour of the text on the items of a NavigationDrawer menu?如何设置 NavigationDrawer 菜单项上的文本颜色?
This is my NavigationDrawer:这是我的 NavigationDrawer:
<!-- The navigation drawer -->
<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:fitsSystemWindows="true"
android:theme="@style/NavigationDrawerStyle"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_menu"/>
And this is my drawer_menu.xml file:这是我的 drawer_menu.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_camera"
android:icon="@drawable/ic_menu_camera"
android:title="Import" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery"
android:title="Gallery" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Tools" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="Share" />
<item
android:id="@+id/nav_send"
android:icon="@drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
I believe this is not a duplicate of this question because it is mandatory for this case to specify the color in styles.xml file.我相信这不是这个问题的重复,因为在这种情况下必须在 styles.xml 文件中指定颜色。
@NullPointerException @空指针异常
in the styles.xml file just use the item name without the custom tag.在styles.xml 文件中只使用没有自定义标签的项目名称。 For example:
例如:
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item><!-- text size in menu-->
<item name="android:textColor">#880ACE0A</item>
<item name="itemTextColor">#880ACE0A</item>
</style>
Cheers干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.