我正在使用android的支持设计库构建一个导航抽屉。我想自定义导航栏中显示的文本的颜色,所以我使用了一个样式来做到这一点。
My 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"
app:theme="@style/NavigationViewTheme"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/menu_navigation" />
我的风格 <style name="NavigationViewTheme" parent="AppTheme">
<item name="textAppearanceListItem">@style/TextAppearance.AppCompat.Body2</item>
<!--CHANGE TEXT COLOR -->
<item name="android:textColorPrimary">@android:color/white</item>
<!-- CHANGE ICON COLOR -->
<item name="android:textColorSecondary">@android:color/white</item>
</style>
我现在要更改的是高亮显示的文本和图标的颜色。我试了很多项目,但都没有变化。
我试过所有这些
<item name="textColorPrimary">@color/primary_text_dark</item>
<item name="textColorSecondary">@color/secondary_text_dark</item>
<item name="textColorTertiary">@color/tertiary_text_dark</item>
<item name="textColorPrimaryInverse">@color/primary_text_light</item>
<item name="textColorSecondaryInverse">@color/secondary_text_light</item>
<item name="textColorTertiaryInverse">@color/tertiary_text_light</item>
<item name="textColorPrimaryActivated">@color/primary_text_dark</item>
<item name="textColorSecondaryActivated">@color/secondary_text_dark</item>
<item name="textColorPrimaryDisableOnly">@color/primary_text_dark_disable_only</item>
<item name="textColorPrimaryInverseDisableOnly">@color/primary_text_light_disable_only</item>
<item name="textColorPrimaryNoDisable">@color/primary_text_dark_nodisable</item>
<item name="textColorSecondaryNoDisable">@color/secondary_text_dark_nodisable</item>
<item name="textColorPrimaryInverseNoDisable">@color/primary_text_light_nodisable</item>
<item name="textColorSecondaryInverseNoDisable">@color/secondary_text_light_nodisable</item>
<item name="textColorHint">@color/hint_foreground_dark</item>
<item name="textColorHintInverse">@color/hint_foreground_light</item>
<item name="textColorSearchUrl">@color/search_url_text</item>
<item name="textColorHighlight">@color/highlighted_text_dark</item>
<item name="textColorHighlightInverse">@color/highlighted_text_light</item>
<item name="textColorLink">@color/link_text_dark</item>
<item name="textColorLinkInverse">@color/link_text_light</item>
<item name="textColorAlertDialogListItem">@color/primary_text_light_disable_only</item>
或者,将app:itemTextColor="@color/navigation_view_color"
设置为您的NavigationView
。
navigation_view_color:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:color="@color/highlighted_color" />
<item android:color="@color/black" />
</selector>
我找到解决办法了。我只需要添加
<item name="colorPrimary">@android:color/holo_red_dark</item>