Here is my root style:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
And here is how I create dialog:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireActivity())
.apply {
setMessage(R.string.dialog_delete_service_message)
setPositiveButton(
R.string.dialog_delete_service_positive_button
) { _, _ ->
listener?.onConfirmed()
}
setNegativeButton(R.string.dialog_delete_service_negative_button, null)
}.create()
}
Fragment is subclass of androidx.fragment.app.DialogFragment
.
Here is how dialog is shown:
I want to show borderless buttons but dialog buttons are bordered. Is any style missing?
AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
A simple dialog containing an DatePicker . This class was deprecated in API level 26.
You can just create a style and apply that theme on the dialog box. So whenever you want to change the color of AlertDialog box, just change color in styles. xml and all the dialog boxes will be updated in the whole application.
Use the MaterialAlertDialogBuilder
new MaterialAlertDialogBuilder(context)
.setTitle("xxxx")
.setMessage("...")
.setPositiveButton("..", null)
.show();
and use this style in your app theme:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
...
<item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog</item>
</style>
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