Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full width alert dialog buttons

I'm trying to get my AlertDialogs to look like this, with the full width button:

enter image description here

I'm following the Google's documentation and it says to use this style:

 R.style.ThemeOverlay_MaterialComponents_MaterialAlertDialog_FullWidthButtons

but I don't have access to that theme:

enter image description here

I have the appropriate dependency added in the project's Gradle file:

implementation 'com.google.android.material:material:1.5.0'

I feel like I'm just missing something obvious.

like image 478
Kris B Avatar asked Oct 28 '25 05:10

Kris B


1 Answers

The implementation of the theme overlays is missing in the library.
You can define it on your own, by:

Declare a full width button style, like:

  <style name="Button.FullWidth" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_weight">1</item>
    <item name="android:maxWidth">@null</item>
  </style>

Declare the theme overlay with full-width button styles:

  <style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog.FullWidthButtons">
    <item name="materialAlertDialogButtonSpacerVisibility">2</item>
    <item name="buttonBarPositiveButtonStyle">@style/Button.FullWidth</item>
    <item name="buttonBarNegativeButtonStyle">@style/Button.FullWidth</item>
    <item name="buttonBarNeutralButtonStyle">@style/Button.FullWidth</item>
  </style>

enter image description here

like image 178
Gabriele Mariotti Avatar answered Oct 29 '25 20:10

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!