MaterialComponents主题警报对话框按钮 [英] MaterialComponents theme alert dialog buttons

本文介绍了MaterialComponents主题警报对话框按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我从支持库切换到com.google.android.material:material:1.0.0

但是现在我有一个问题,在此页面中有一条注释

我正在使用的主题

Theme.MaterialComponents.Light.NoActionBar

完全按照该注释中的说明进行操作,它将AlertDialog Buttons替换为MaterialButtons,但是问题是默认情况下MaterialButtons是彩色背景,现在这些按钮看起来像这样:

如何使它们再次变得无边界和无背景?

PS我正在使用警报生成器来创建警报对话框:

android.app.AlertDialog.Builder

解决方案

我知道是什么导致了此问题.我需要使用其他AlertDialog类:

androidx.appcompat.app.AlertDialog

当我切换到这一步时,一切都按预期开始工作.这是我找到解决方案的地方:

https://github.com/material-components/material- components-android/issues/162

Recently I switched from support library to com.google.android.material:material:1.0.0

But now I have a problem, in this pages there's a note https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md

Note: Using a Material Components theme enables a custom view inflater which replaces default components with their Material counterparts. Currently, this only replaces Button XML components with MaterialButton.

And the theme I am using

Theme.MaterialComponents.Light.NoActionBar

does exactly what it says in that note, it replaces AlertDialog Buttons to MaterialButtons but the problem is that by default MaterialButtons are colored background and now the buttons looks like this:

How can I make them borderless and backgroundless again?

PS I am using alert builder to create alert dialogs:

android.app.AlertDialog.Builder

解决方案

I figured out what was causing this problem. I need to use different AlertDialog class:

androidx.appcompat.app.AlertDialog

When I switched to this everything started working as expected. Here's where I found the solution:

https://github.com/material-components/material-components-android/issues/162

这篇关于MaterialComponents主题警报对话框按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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