Search code examples
androidandroid-layoutandroid-themeandroid-popupwindow

Android support library strange theme behavior


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.


Solution

  • 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.