Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing appcompat alertdialog accent color made all dialogs smaller

So I wanted to change my alertdialogs accent color, I added this to my styles.xml

<style name="AppTheme.AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

and this into my base style:

<item name="android:alertDialogTheme">@style/AppTheme.AlertDialogTheme</item>

Color is changed, thats cool, but now all my dialogs are smaller. How can I retain the size while changing the color?

Here is before/after album.

like image 419
kovacevic-s Avatar asked Dec 19 '22 06:12

kovacevic-s


1 Answers

From looking at the google iosched code, the alertdialog theme needs to inherit from Theme.AppCompat.Light.Dialog.Alert not just Theme.AppCompat.Light.Dialog .

Two caveats. One, the result is wider than it was before, but at least it's not as narrow as wrap content. Two, this caused weird behavior on pre-L devices. Ultimately, I ended up creating all alerts with

        AlertDialog.Builder dialog = new AlertDialog.Builder(context,
            R.style.Theme_AppCompat_Light_Dialog_Alert_Custom

This worked fine for Alert Dialogs and Dialogs but for some reason it did not theme Progress Dialogs. I had to remove android:alertDialogTheme from my base theme and put it in a v21/styles.xml only in order to theme Progress Dialogs without bad behavior (double backgrounds) on Pre-L devices.

like image 99
sbaar Avatar answered Apr 27 '23 00:04

sbaar