Wrong button style when creating AlertDialog with androidx DialogFragment

你。 提交于 2020-02-02 03:08:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!