【问题标题】:Wrong button style when creating AlertDialog with androidx DialogFragment使用 androidx DialogFragment 创建 AlertDialog 时按钮样式错误
【发布时间】:2019-12-30 09:57:54
【问题描述】:

这是我的根风格:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

这是我创建对话框的方式:

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()
    }

片段是androidx.fragment.app.DialogFragment 的子类。

以下是对话框的显示方式:

我想显示无边框按钮,但对话框按钮有边框。是否缺少任何样式?

【问题讨论】:

    标签: android material-design android-alertdialog androidx material-components-android


    【解决方案1】:

    使用MaterialAlertDialogBuilder

    new MaterialAlertDialogBuilder(context)
                .setTitle("xxxx")
                .setMessage("...")
                .setPositiveButton("..", null)
                .show();
    

    并在您的应用主题中使用此样式:

     <!-- Base application theme. -->
     <style name="AppTheme" parent="Theme.MaterialComponents.Light">
        ...
        <item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog</item>
     </style>
    

    【讨论】:

    • 有没有不使用不同类的方法?
    猜你喜欢
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    相关资源
    最近更新 更多