0

,因爲昨晚我期待我的申請主題的這種怪異的行爲: 彈出菜單出現黑色背景與AlertDialogs用白色文本。Android的支持庫奇怪的主題行爲

Black popup menu backgroundWhite text color on alert dialog

順便說一句,我的繼承人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> 

任何想法什麼是錯?我只想讓彈出式菜單再次使用默認的燈光主題,並且提醒對話框使用黑色的前景色。

回答

0

OK我解決了這個問題。我將應用程序上下文傳遞給彈出菜單和alertdialog構建器的構造函數。這似乎會導致應用程序主題出現問題。我只是將getApplicationContext()更改爲getActivity(),它工作。

1

你爲什麼認爲這是錯的?

PopupWindow背景是暗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> 

如果你想改變它 - 你需要重寫彈出窗口的風格爲您的主題:

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

警報對話框獲取同一定製方式

+0

哎帕維爾,感謝您的回覆。我創建了一個新的項目,以測試出的東西,有我的彈出菜單的背景是淺灰色的像我想有它在我的項目too.The風格也從Theme.AppCompat.Light.DarkActionBar繼承,所以它不是由默認的黑色 – tobs