使用androidx DialogFragment创建AlertDialog时按钮样式错误 [英] Wrong button style when creating AlertDialog with androidx DialogFragment

查看:706
本文介绍了使用androidx DialogFragment创建AlertDialog时按钮样式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的根风格:

<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是androidx.fragment.app.DialogFragment的子类.

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?

推荐答案

使用

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

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>

这篇关于使用androidx DialogFragment创建AlertDialog时按钮样式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆