Mulgard Mulgard - 5 months ago 65
Android Question

Cant change Popup Menu

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" />

Answer

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" />
Comments