Reputation: 1325
I've recently switch the AlertDialog
instances in my app to use android.support.v7.app.AlertDialog
, but am having a problem applying a custom theme and style to the alert dialogs.
In my styles.xml I have the following style:
<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/theme_accent_1</item>
<item name="background">@color/theme_component_background</item>
<item name="android:background">@color/theme_component_background</item>
</style>
In my themes.xml I have the following set in my theme as required:
<item name="android:alertDialogTheme">@style/AlertDialog</item>
For some reason the custom styles are never applied to the AlertDialog
instances, and they remain the default Theme.AppCompat.Dialog.Alert
theme.
If I explicitly set the style resource to use as follows, it does work:
AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity(), R.style.AlertDialog);
Is there no way to set the default style across the entire theme and not have to specify the theme in the Builder
constructor?
Upvotes: 5
Views: 5764
Reputation: 1325
As per Pankaj Kumar's response, the link details the solution, which is to have both declarations with and without the "android:" prefix in the name attribute.
<item name="android:alertDialogTheme">@style/AlertDialog</item>
<item name="alertDialogTheme">@style/AlertDialog</item>
Upvotes: 8