“材料"与“材料组件" [英] 'Material' vs 'MaterialComponents'

本文介绍了“材料"与“材料组件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Theme.Material ... Theme.MaterialComponents ... 有什么区别?

我正在创建警报对话框,当我使用以下方法创建它时:

I am creating an alert dialogue and when I create it using:

新的AlertDialog.Builder(上下文,android.R.style.Theme_Material_Light_Dialog_Alert);

我得到"colorAccent"按钮上的彩色文本.

I get "colorAccent" coloured text on the buttons.

但是,当我使用以下方法创建对话框时:

However when I create the dialog using:

返回新的AlertDialog.Builder(context,R.style.myTheme);

具有:<样式名="myTheme";parent =" @ style/Theme.MaterialComponents.Light.Dialog.Alert"//gt;

我似乎收到了紫色的文字.这些有什么区别?

I seem to get purple coloured text. What is the difference between these?

最后,如果我要导出"myTheme",从 Theme.AppCompat ... (而不是 Theme.MaterialComponent ... )获得白色文本.这是怎么回事?

And finally if I were to derive "myTheme" from Theme.AppCompat... (instead of Theme.MaterialComponent...) I get white text. What is going on here?

推荐答案

Theme.Material 由Android从API 21开始提供.
Theme.MaterialComponents 由材料组件库提供.
它们是完全不同的.

The Theme.Material is provided by Android starting with API 21.
The Theme.MaterialComponents is provided by the Material Components library.
They are completely different.

如果要使用材料组件库,最好的方法是使用 MaterialAlertDialogBu​​ilder .

If you want to use the Material Components Library the best way is to use the MaterialAlertDialogBuilder.

return new MaterialAlertDialogBuilder(context, R.style.myTheme);

并继承以下主题的叠加层:

and inherit the theme overlay from:

<style name="myTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">

在这里您可以检查所有应用于主题的默认属性.

Here you can check all the default attributes applied to the theme.

这篇关于“材料"与“材料组件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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