MaterialButton和简单Button之间有什么区别吗? [英] Is any difference between a MaterialButton and a simple Button?

本文介绍了MaterialButton和简单Button之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将 Theme.MaterialComponents.Light 设置为我的主要主题,那么如果我在xml布局中使用这两个按钮,它们之间会有什么区别吗?

If I set Theme.MaterialComponents.Light as my main theme, will be any difference between these two buttons if I use them in an xml layout?

<Button />

<com.google.android.material.button.MaterialButton />

如我所见,它们的行为均与MaterialButtons相同. 如果要获取旧的普通按钮的行为,则必须使用:

As I saw they behave both as MaterialButtons. If I want to get the behavior of the old plain button, I have to use:

<androidx.appcompat.widget.AppCompatButton />

提前谢谢!

推荐答案

如果您使用的是 MaterialComponents主题,则<Button /><com.google.android.material.button.MaterialButton />之间的没有区别

If you are using a MaterialComponents Theme there is no difference between <Button /> and <com.google.android.material.button.MaterialButton />.

启用了自动充气,该将在运行时用<com.google.android.material.button.MaterialButton替换 <Button.

The MaterialComponentsViewInflater replaces some framework widgets with Material Components ones at inflation time, provided if a MaterialComponents theme is in use.
Something similar happens also with AppCompat (you can check that MaterialComponentsViewInflater extends AppCompatViewInflater).

这意味着,如果您使用的是MaterialComponents主题,则在运行时将<Button替换为<com.google.android.material.button.MaterialButton.

It means that, the <Button is replaced <com.google.android.material.button.MaterialButton at runtime, if you are using a MaterialComponents Theme.

如果我想获得旧的普通按钮的行为,则必须使用: <androidx.appcompat.widget.AppCompatButton />.

If I want to get the behavior of the old plain button, I have to use: <androidx.appcompat.widget.AppCompatButton />.

这是一个选择,但不是必须的.
这取决于您要实现的目标.您还可以配置自定义样式,因为Widget.MaterialComponents.Button样式是由Widget.AppCompat.Button样式继承的.

It is an option, but not necessarily.
It depends by what you want to achieve. You can also config a custom style since the Widget.MaterialComponents.Button style inherits by Widget.AppCompat.Button style.

这篇关于MaterialButton和简单Button之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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