导航抽屉,支持设计。突出显示项目的文本颜色
Navigation Drawer, support design. Text color of highlighted item
我正在使用 android 的支持设计库构建导航抽屉。我想自定义该导航抽屉中显示的文本的颜色,因此我使用了一种样式来实现。
我的导航抽屉。
<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>
我找到了解决办法。我只需要添加
<item name="colorPrimary">@android:color/holo_red_dark</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>
我正在使用 android 的支持设计库构建导航抽屉。我想自定义该导航抽屉中显示的文本的颜色,因此我使用了一种样式来实现。
我的导航抽屉。
<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>
我找到了解决办法。我只需要添加
<item name="colorPrimary">@android:color/holo_red_dark</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>