I am trying to change the style of the popup dialog of a ListPreference like I saw in this answer. For example I want a different background colour for the dialog.
So far I tried to apply my custom style with:
<item name="android:dialogTheme">@style/AlertDialogStyle</item>
<item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
<item name="android:dialogPreferenceStyle">@style/AlertDialogStyle</item>
<style name="AlertDialogStyle" parent="AlertDialog.AppCompat">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">@color/lightGrey</item>
<item name="android:background">@color/cardBackground</item>
<item name="android:popupBackground">@color/cardBackground</item>
<item name="android:windowBackground">@color/cardBackground</item>
<item name="android:itemBackground">@color/cardBackground</item>
</style>
But my style is still not applied/background colour is unchanged.
This is how the popup dialog of my ListPreference looks at the moment:
And this is the color theme I want to archive (basically the same theme I use for my other dialogs):
To quickly reproduce my issue -> my project is on github
Answering my own question. In the end it was as simple as replacing:
<item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
with
<item name="alertDialogTheme">@style/AlertDialogStyle</item>
I think you are mixing the things in your markup. alertDialogStyle and alertDialogTheme both are different.
Customizing the alert dialog theme you should create your Dialog theme, a theme that should probably extend @android:style/Theme.Dialog.Alert
<item name="android:dialogTheme">@style/dialogAlertTheme</item>
<item name="android:alertDialogTheme">@style/dialogAlertTheme</item>
<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
<item name="android:dialogPreferenceStyle">@style/AlertDialogStyle</item>
<style name="dialogAlertTheme" parent="@android:style/Theme.Dialog.Alert">
<item name="android:windowBackground">[...]</item>
[...]
</style>
<style name="AlertDialogStyle" parent="AlertDialog.AppCompat">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">@color/lightGrey</item>
<item name="android:background">@color/cardBackground</item>
<item name="android:popupBackground">@color/cardBackground</item>
<item name="android:windowBackground">@color/cardBackground</item>
<item name="android:itemBackground">@color/cardBackground</item>
</style>
Note-1. Customizing the alert dialog style is limited to providing (background) drawables.
Note-2. Customizing the alert dialog theme opens a method to provide attributes such as windowBackground, windowTitleStyle and such, but you need an Android version which supports the alertDialogThem attribute/item for themes
Explanation for your Answer: why it is working if you remove the android:
from android:alertDialogTheme
<item name="alertDialogTheme">@style/AlertDialogStyle</item>
Now it is the standard way of overriding AlertDialog styles. It was part of the lib as the AlertDialog wouldn't use the accent color from the main theme, but has been removed since in v24.2.0.0 because the Android team fixed this behavior.
Issue Refrence: https://github.com/Gericop/Android-Support-Preference-V7-Fix/issues/52#issuecomment-255759293
Change Refrence: https://github.com/Gericop/Android-Support-Preference-V7-Fix/commit/a6082cb0a508f5e0305a626c9a2a841e943ef8f6#diff-483bbb12192b1b74adadc9b4076b203b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With