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" />
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.
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.
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
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.
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With