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