Reputation: 10589
I defined the following style for my app:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorAccent">@color/accentColor</item>
<item name="android:textColorPrimary">@color/textcolorsecundary</item>
<item name="android:textColorSecondary">@color/textcolorsecundary</item>
<item name="android:popupMenuStyle">@style/AppTheme.Base.PopupMenu</item>
</style>
<style name="AppTheme.Base.PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@color/primaryColor</item>
</style>
</resources>
Unfortunately the style for the background of the popup menu (for example in the options menu) does not change at all. The text color is set correclty but the popupBackground
is totally ignored it stays always white.
So how can i change it to my color?
EDIT
Maybe it is a problem that i use a custom toolbar?
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:background="@color/primaryColor"
app:theme="@style/AppTheme" />
Upvotes: 2
Views: 1249
Reputation: 133
To change the popup menu background color, and thanks to Mulgard's answer, I did the following after adapting the accepted answer's source code a little bit :
So in activity_main.xml
:
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/CustomPopupMenu" />
And in styles.xml
:
<!-- PopupMenu styles -->
<style name="CustomPopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:background">@color/gray</item>
<item name="android:textColor">@color/white</item>
</style>
That's all, it worked for me. I hope this may help you.
Upvotes: 1
Reputation: 10589
Solved after hours of work...
styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorAccent">@color/accentColor</item>
<item name="android:textColorPrimary">@color/textcolorsecundary</item>
<item name="android:textColorSecondary">@color/textcolorsecundary</item>
<item name="android:actionModeBackground">@color/primaryColor</item>
</style>
<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/textcolorsecundary</item>
<item name="actionMenuTextColor">@color/textcolorsecundary</item>
<item name="android:textColorSecondary">@color/textcolorsecundary</item>
<item name="android:background">@color/primaryColor</item>
</style>
</resources>
toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<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="?android:attr/actionBarSize"
android:elevation="2dp"
android:focusable="false"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/AppTheme.Toolbar" />
Upvotes: 4
Reputation: 75788
Please try this
<style name="AppTheme.Base.PopupMenu" parent="@style/Theme.AppCompat">
<item name="android:popupBackground">@color/primaryColor</item>
</style>
Upvotes: 2