'Set MaterialAlertDialog horizontal margins

I wrote a custom theme for all my (Material)AlertDialogs and applied it to APP's theme.

<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">#FFFFFF</item>
    ...
    <item name="alertDialogTheme">@style/MyDialogStyle</item>
</style>

<style name="MyDialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
    <item name="android:textColor">@color/colorBlue</item>
    ...
</style>

How can I set (for example reduce) the external horizontal margin (both Start and End) of the AlertDialog from the windows borders?

In example image the red line is the actual margin, and the blue line is the wanted margin.

enter image description here

I don't want to set it programmatically, but globally from the resources file.



Solution 1:[1]

With a MaterialComponents theme you can override these dimens in your theme:

<dimen name="mtrl_alert_dialog_background_inset_start">4dp</dimen>
<dimen name="mtrl_alert_dialog_background_inset_end">4dp</dimen>

enter image description here

Default:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabriele Mariotti