Android toolbar menu text color
I'm trying to change the text color of the toolbar menu item here, but it doesn't work. Here's my style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="toolbarStyle">@style/AppTheme.ToolbarStyle</item>
<item name="buttonStyle">@style/AppTheme.ButtonStyle</item>
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
<style name="AppTheme.ToolbarStyle" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">@color/colorPrimary</item>
<item name="titleTextColor">@android:color/white</item>
<item name="titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title
</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
layout xml:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/app_name"
app:titleMarginStart="@dimen/margin_l"
/>
I tried to set the toolbar theme directly to the xml, but the menu item still came back. Is there a solution for this?
+3
source to share
3 answers
In your theme file, you must specify:
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionMenuTextColor">@color/text_color</item>
...
</style>
and apply above the theme to the toolbar view as shown in the picture android:theme="@style/AppTheme.ActionBar"
detailed example:
<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/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_gravity="top"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/AppTheme.ActionBar"/>
-1
source to share
Create a theme for the toolbar
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionMenuTextColor">@color/your_color_code</item>
...
</style>
and apply this theme to the toolbar view like this:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
android:theme="@style/AppTheme.ActionBar"/>
-1
source to share