Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Toolbar menu text color

I'm trying to change my Toolbar's menu item text color 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 have tried to set the Toolbar theme directly in xml, but the menu item is still back. Is there a solution to this?

enter image description here

like image 845
Євген Гарастович Avatar asked Apr 07 '17 10:04

Євген Гарастович


People also ask

How do I change the menu text color?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 4 – Right-click on res, select New -> Android Resource Directory – menu.

How do I change the color of my toolbar menu?

Open the colors. xml file by navigating to the app -> res -> values -> colors. xml. Create a color tag inside the resources tag with a name and set a color with its hex code.

How do I change the color of my app bar text?

Step 1: Locate the MaterialApp widget. Step 2: Inside the MaterialApp, add the theme parameter with ThemeData class assigned. Step 3: Inside the ThemeData add the appBarTheme parameter and then assign the AppBarTheme class. Step 4: Inside the AppBarTheme , specify the foregroundColor parameter and set the color.

How do you change the color of the tool bar on Android?

Just go to res/values/styles.edit the xml file to change the color of action bar.


2 Answers

Add these lines in your AppTheme style

<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
like image 127
Abid Khan Avatar answered Sep 25 '22 01:09

Abid Khan


Having a material toolbar you can play with styling modifying text title and menu texts as follows:

<com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:background="@android:color/white"
    android:elevation="6dp"
    android:theme="@style/App.ToolbarStyle"
    app:titleTextAppearance="@style/App.ToolbarTitleTex"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:menu="@menu/create_item_menu"
    app:titleTextColor="@android:color/black" />

Where this style lets you change the color of the icon of the left:

<style name="App.ToolbarStyle" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
    <item name="colorOnPrimary">@color/colorPrimary</item>
</style>

Also you can change the title text appearance with another style:

<style name="App.ToolbarTitleTex" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
    <item name="android:textSize">18sp</item>
    <item name="fontFamily">@font/roboto_bold</item>
</style>

And finally to change the menu item style you need to add this item property to the main style/theme of the app (the one you set in the AndroidManifest file:

<item name="actionMenuTextAppearance">@style/App.ToolbarMenuItem</item>

With:

<style name="App.ToolbarMenuItem" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
    <item name="android:textSize">14sp</item>
    <item name="fontFamily">@font/roboto_bold</item>
    <item name="textAllCaps">true</item>
    <item name="android:textStyle">bold</item>
</style>

The final result would be something like this: enter image description here

like image 43
Carlos Daniel Avatar answered Sep 23 '22 01:09

Carlos Daniel