问题
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?
回答1:
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>
来源:https://stackoverflow.com/questions/57654013/wrong-button-style-when-creating-alertdialog-with-androidx-dialogfragment