0

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.

adneal
  • 30,484
  • 10
  • 122
  • 151
tobs
  • 699
  • 2
  • 8
  • 24

2 Answers2

1

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

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83
  • hey pavel, thanks for your reply. I created a new project to test out something and there my popup menu background is light gray like I want to have it in my project too.The style also inherits from Theme.AppCompat.Light.DarkActionBar, so its not black by default – tobs Apr 03 '14 at 21:28
0

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.

tobs
  • 699
  • 2
  • 8
  • 24