Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing default Theme.AppCompat.Dialog.Alert with android.support.v7.app.AlertDialog

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?

like image 543
activelogic Avatar asked Mar 15 '23 21:03

activelogic


1 Answers

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>
like image 111
activelogic Avatar answered Apr 29 '23 09:04

activelogic