Question

since last night I'm expecting this weird behavior of my application theme: Popup menus appear with black background and AlertDialogs with white text color.

Black popup menu background White text color on alert dialog

By the way, heres my styles.xml:

<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>

        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar"
        parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/action_bar_background</item>

        <!-- Support library compatibility -->
        <item name="background">@drawable/action_bar_background</item>
    </style>

</resources>

Any idea whats wrong? I just want the popup menu to use the default light theme again and the alert dialog to use a black foreground color.

Was it helpful?

Solution 2

OK I solved the problem. I passed the application context to both popup menu and alertdialog builder's constructor. This seems to cause problems with application themes. I simply changed getApplicationContext() to getActivity() and it worked.

OTHER TIPS

Why do you think it is wrong?

PopupWindow background is dark in Theme.Light:

<style name="Widget.PopupWindow">
    <item name="android:popupBackground">@android:drawable/editbox_dropdown_background_dark</item>
    <item name="android:popupAnimationStyle">@android:style/Animation.PopupWindow</item>
</style>

If you want to change it - you need to override popup window style for your theme:

<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
    <item name="android:popupWindowStyle">@style/YourCustomStyle</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="YourCustomStyle" parent="@android:style/Widget.PopupWindow">
    <item name="android:popupBackground">@drawable/your_background</item> 
</style>

Alert dialog gets customized in the same way

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top