How do I achieve Alert Dialog Button style like this :
Do I have to create a custom "Dialog" or this can be achieved via AlertDialog theming?
How do I achieve Alert Dialog Button style like this :
Do I have to create a custom "Dialog" or this can be achieved via AlertDialog theming?
Just use the MaterialAlertDialogBuilder
using a custom style:
new MaterialAlertDialogBuilder(MainActivity.this,
R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog)
.setTitle("Keep backup off?")
.setMessage("Backup is free and unlimited at high quality")
.setPositiveButton("Turn on", null)
.setNegativeButton("Keep off", /* listener = */ null)
.show();
Use the buttonBarPositiveButtonStyle
and buttonBarNegativeButtonStyle
attributes to change the default color.
In this case you can use a filled button (Widget.MaterialComponents.Button
) for the positive button and a Text Button (Widget.MaterialComponents.Button.TextButton.Dialog
) for the negative button.
<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
</style>
<style name="PositiveButtonStyle" parent="@style/Widget.MaterialComponents.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">@color/primaryDarkColor</item>
</style>
<style name="NegativeButtonStyle" parent="@style/Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/primaryDarkColor</item>
</style>