如何在工具栏主题上设置 textColorSecondary
How to set textColorSecondary on toolbar theme
我已经尝试了好几天来解决工具栏中多个 UI 元素颜色错误的问题。如果你看看下面的图片,你就会明白我的意思:
应该是白色的元素是黑色的,我只是想不出如何通过我的主题解决这个问题。
这是我的themes.xml(抱歉里面乱七八糟,但主题真的很难):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.GuidelinesCompat.Light.DarkToolbar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="toolbarStyle">@style/AppTheme.NoActionBar.ToolbarStyle</item>
<item name="actionModeStyle">@style/AppTheme.NoActionBar.ActionModeStyle</item>
<item name="searchViewStyle">@style/AppTheme.NoActionBar.SearchViewStyle</item>
<!--<item name="android:actionModeBackground">@color/bg_action_mode</item>-->
<!--<item name="android:textColorSecondary">@color/white</item>-->
</style>
<style name="AppTheme.ActionBar">
<item name="android:windowActionModeOverlay">true</item>
</style>
<!-- Base toolbar theme. -->
<style name="AppTheme.NoActionBar.ToolbarStyle" parent="Widget.GuidelinesCompat.Toolbar">
<item name="titleTextAppearance">@style/AppTheme.NoActionBar.ToolbarTitleTextAppearance</item>
</style>
<style name="AppTheme.NoActionBar.ToolbarTitleTextAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<!-- Base Action Mode styles -->
<style name="AppTheme.NoActionBar.ActionModeStyle" parent="Widget.GuidelinesCompat.ActionMode">
<item name="background">@color/bg_action_mode</item>
<!--<item name="android:actionModeBackground">@color/bg_action_mode</item>-->
<!--<item name="android:actionOverflowButtonStyle">@style/ActionModeTitleTextStyle</item>-->
<!--<item name="statusBarColor">@color/grey_100</item>-->
</style>
<style name="ActionModeTitleTextStyle" parent="Widget.GuidelinesCompat.ActionButton.Overflow">
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<style name="AppTheme.NoActionBar.SearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Sets the search icon -->
<item name="searchIcon">@drawable/ic_search_white_24dp</item>
<!-- Gets rid of the "underline" in the text -->
<!--<item name="queryBackground">@color/white</item>-->
<!-- Gets rid of the search icon when the SearchView is expanded -->
<!--<item name="searchHintIcon">@null</item>-->
<!-- The hint text that appears when the user has not typed anything -->
<!--<item name="queryHint">@string/menu_examination_search_hint</item>-->
<item name="android:textAppearance">@style/SearchViewTextAppearance</item>
</style>
<style name="SearchViewTextAppearance">
<item name="android:textColorHint">@color/white</item>
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<!-- Theme applied to LoginActivity and SignUpActivity -->
<style name="AppTheme.Login" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="android:textColorHint">@color/iron</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="colorControlNormal">@color/iron</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
<item name="colorButtonNormal">@color/colorPrimaryDarker</item>
</style>
<style name="AppTheme.NavigationView">
<item name="android:textColorSecondary">@color/colorTextSecondary</item>
</style>
<!-- Theme applied to Textview in LoginActivity and SignUpActivity -->
<style name="WhiteText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/white</item>
</style>
<!-- Animations applied to dialog when entering or exiting -->
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
</style>
我发现如果我在我的 AppTheme.NoActonBar 中设置 textColorSecondary,我的所有控件都正确地着色为白色,但这给我的所有对话框带来了麻烦,现在它们也将 textColorSecondary 设置为白色。
我希望有人能告诉我一个解决方案,因为我没有想法。
试试这个 here。
在您的工具栏布局中:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
app:popupTheme="@style/ToolBarPopupStyle"
android:background="@color/actionbar/>
你的风格:
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
我已经尝试了好几天来解决工具栏中多个 UI 元素颜色错误的问题。如果你看看下面的图片,你就会明白我的意思:
应该是白色的元素是黑色的,我只是想不出如何通过我的主题解决这个问题。
这是我的themes.xml(抱歉里面乱七八糟,但主题真的很难):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.GuidelinesCompat.Light.DarkToolbar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorBackground</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="toolbarStyle">@style/AppTheme.NoActionBar.ToolbarStyle</item>
<item name="actionModeStyle">@style/AppTheme.NoActionBar.ActionModeStyle</item>
<item name="searchViewStyle">@style/AppTheme.NoActionBar.SearchViewStyle</item>
<!--<item name="android:actionModeBackground">@color/bg_action_mode</item>-->
<!--<item name="android:textColorSecondary">@color/white</item>-->
</style>
<style name="AppTheme.ActionBar">
<item name="android:windowActionModeOverlay">true</item>
</style>
<!-- Base toolbar theme. -->
<style name="AppTheme.NoActionBar.ToolbarStyle" parent="Widget.GuidelinesCompat.Toolbar">
<item name="titleTextAppearance">@style/AppTheme.NoActionBar.ToolbarTitleTextAppearance</item>
</style>
<style name="AppTheme.NoActionBar.ToolbarTitleTextAppearance" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<!-- Base Action Mode styles -->
<style name="AppTheme.NoActionBar.ActionModeStyle" parent="Widget.GuidelinesCompat.ActionMode">
<item name="background">@color/bg_action_mode</item>
<!--<item name="android:actionModeBackground">@color/bg_action_mode</item>-->
<!--<item name="android:actionOverflowButtonStyle">@style/ActionModeTitleTextStyle</item>-->
<!--<item name="statusBarColor">@color/grey_100</item>-->
</style>
<style name="ActionModeTitleTextStyle" parent="Widget.GuidelinesCompat.ActionButton.Overflow">
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<style name="AppTheme.NoActionBar.SearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Sets the search icon -->
<item name="searchIcon">@drawable/ic_search_white_24dp</item>
<!-- Gets rid of the "underline" in the text -->
<!--<item name="queryBackground">@color/white</item>-->
<!-- Gets rid of the search icon when the SearchView is expanded -->
<!--<item name="searchHintIcon">@null</item>-->
<!-- The hint text that appears when the user has not typed anything -->
<!--<item name="queryHint">@string/menu_examination_search_hint</item>-->
<item name="android:textAppearance">@style/SearchViewTextAppearance</item>
</style>
<style name="SearchViewTextAppearance">
<item name="android:textColorHint">@color/white</item>
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
</style>
<!-- Theme applied to LoginActivity and SignUpActivity -->
<style name="AppTheme.Login" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="android:textColorHint">@color/iron</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="colorControlNormal">@color/iron</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
<item name="colorButtonNormal">@color/colorPrimaryDarker</item>
</style>
<style name="AppTheme.NavigationView">
<item name="android:textColorSecondary">@color/colorTextSecondary</item>
</style>
<!-- Theme applied to Textview in LoginActivity and SignUpActivity -->
<style name="WhiteText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/white</item>
</style>
<!-- Animations applied to dialog when entering or exiting -->
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
</style>
我发现如果我在我的 AppTheme.NoActonBar 中设置 textColorSecondary,我的所有控件都正确地着色为白色,但这给我的所有对话框带来了麻烦,现在它们也将 textColorSecondary 设置为白色。
我希望有人能告诉我一个解决方案,因为我没有想法。
试试这个 here。
在您的工具栏布局中:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
app:popupTheme="@style/ToolBarPopupStyle"
android:background="@color/actionbar/>
你的风格:
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>