'Full width alert dialog buttons
I'm trying to get my AlertDialogs
to look like this, with the full width button:
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:
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.
Solution 1:[1]
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>
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 |