A
A
AndreyRafalsky132019-02-23 20:48:23
Android
AndreyRafalsky13, 2019-02-23 20:48:23

Why are styles not included for popupMenu?

Help solve the problem. I want to create a popup-menu with a dark background and a white font color. But the user style is not connected for some reason to the menu.
styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@null</item>
        <item name="popupMenuStyle">@style/AppTheme.darkPopupStyle</item>
    </style>

    <style name="AppTheme.darkPopupStyle" parent="Widget.AppCompat.PopupMenu">
        <item name="android:itemBackground">@drawable/popup_drawable</item>
        <item name="android:textColor">@android:color/white</item>
    </style>

</resources>

popup_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <color
            android:color="@android:color/darker_gray"/>
    </item>
    <item>
        <color
            android:color="@android:color/black"/>
    </item>
</selector>

The code where I create a menu object and connect styles to it:
ContextWrapper wrapper = new ContextThemeWrapper(context, R.style.AppTheme_darkPopupStyle);
                PopupMenu menu = new PopupMenu(wrapper, v);

Use android.support.v7.widget.PopupMenu
Help solve the problem. Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question