Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar options menu background color

I am using the toolbar for android. I just want to change the background color of the overflow menu. But it is not changing.

Style xml

<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
    <item name="popupTheme">@style/PopupMenuStyle</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="PopupMenuStyle" parent="android:Widget.Holo.Light.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
</style>

Toolbar XML

    <android.support.v7.widget.Toolbar
    android:id="@+id/tool_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/MyDarkToolbarStyle" />
like image 476
WISHY Avatar asked Mar 17 '15 09:03

WISHY


People also ask

How do I change the text color on the pop up menu in Android?

This example demonstrates how do I change the text color of the menu item in android. 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.

How can I change the color of my toolbar title in Android?

Go to the app > res > values > themes > themes. xml file and add the following line inside the <resources> tag. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar. This method sets the toolbar as the app bar for the activity.

How to change the background color of the options menu in Android?

This example demonstrates how to change the background color of the options menu in Android. 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 3 − Add the following code to res/menu/menu_items.xml

How do I change the color of my toolbar?

Move the black arrow on the right side to select the color darkness. Move the swatch icon around the color display to pick a color. j. Click on "OK" once the new toolbar color has been chosen. This will close the color swatch window.

How do I change the background color in Windows 10?

Select Personalisation from the left menu. 2. Click Colour to continue. 3. Under the A ccent colour section, select the colour you want to use. 4. Turn on the button next to Show accent color on Start and taskbar.

How to customize the taskbar colour in Windows 11?

Turn on the button next to Show accent color on Start and taskbar. After these steps, you will discover that the colour of your taskbar is changed to your selected one. How to Customize the Taskbar Colour in Windows 11? The system only displays a few colour selections for you.


2 Answers

To change the toolbar options menu color, add this to your toolbar element

app:popupTheme="@style/MyDarkToolbarStyle"

Then in your styles.xml define the popup menu style

<style name="MyDarkToolbarStyle" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:colorBackground">@color/mtrl_white_100</item>
    <item name="android:textColor">@color/mtrl_light_blue_900</item>
</style>

Note that you need to use colorBackground not background. The latter would be applied to everything (the menu itself and each menu item), the former applies only to the popup menu.

like image 136
Apurva Avatar answered Sep 28 '22 04:09

Apurva


Edit:

if you just want a white overflow popup menu just do this

<android.support.v7.widget.Toolbar
    android:id="@+id/tool_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    app:theme="@style/MyDarkToolbarStyle"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"" />

and remove the redundant popupTheme your Style xml

<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
     <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

You should also include this in your top (parent) Layout

xmlns:app="http://schemas.android.com/apk/res-auto"
like image 36
cozeJ4 Avatar answered Sep 28 '22 04:09

cozeJ4