这些在Material Button Google参考文档中的一堆不存在的方法是什么?

huangapple go评论55阅读模式
英文:

What are these bunch of non-existence methods in material button google reference?

问题

我尝试以编程方式更改材料按钮图标,为此,Stackoverflow上的帖子建议使用名为setCompoundDrawablesWithIntrinsicBounds的易碎方法。

我试图在官方网站上查找更多方法,例如developer.android.com和GitHub,但奇怪的是,我找到的方法和XML属性根本不存在。例如,此页面建议以下内容:

这些在Material Button Google参考文档中的一堆不存在的方法是什么?

据我所知,XML中不存在app:MaterialButton_iconandroid:MaterialButton_icon属性。而且在Java 8中也没有setIconResource(int)方法。

这些奇怪的参考文档是什么?

英文:

I tried to change material button icon programmatically and for this, Stackoverflow posts suggest that there is a frangible method called setCompoundDrawablesWithIntrinsicBounds.

I tried to find more methods on the official sites e.g. developer.android.com and GitHub, But oddly I find methods and XML-attributes that do not exists at all. For example this page suggests the following:

这些在Material Button Google参考文档中的一堆不存在的方法是什么?

As I know, There is no app:MaterialButton_icon nor android:MaterialButton_icon attributes for XML. Also there is no setIconResource(int) method (in Java 8).

What are these odd reference documents?

答案1

得分: 2

在官方网站上看到的名称只是用于该视图的自定义可样式化属性名称。

您可以在此链接中了解更多信息:https://developer.android.com/develop/ui/views/layout/custom-views/create-view#customattr

在XML中,您只需简单地使用 app:icon="@drawable/icon",而不是例如 app:MaterialButton_icon="@drawable/icon"

如果您在代码中找不到这些方法,请检查您的项目依赖项,确保它具有Google Material依赖项。或者如果您在使用Kotlin,像 setIcongetIcon 这样的方法只是 icon 属性,没有任何函数。

希望这可以解决您的问题。

英文:

The names that you see on the official site are just custom styleable attribute names which is used for that View.

You can learn more about it in this link: https://developer.android.com/develop/ui/views/layout/custom-views/create-view#customattr

In XML, you can just simply use app:icon="@drawable/icon" instead of app:MaterialButton_icon="@drawable/icon" for example.

If you cannot find those methods in the code, please check your project dependencies to make sure it has Google Material dependency. Or if you are using Kotlin, the method like setIcon or getIcon is simply icon property without any functions.

Hope this can resolve your problems

答案2

得分: 1

我不知道那个突出显示的 MaterialButtom_icon 属性是什么,但似乎您在您的Java代码中使用了 Button 而不是 MaterialButton。材料按钮的正确声明如下:

MaterialButton button = findViewById(R.id.your_material_button_id);

而不是

Button button = findViewById(R.id.your_material_button_id);

通过正确的声明,我们有:

这些在Material Button Google参考文档中的一堆不存在的方法是什么?

英文:

I don't know what is that highlighted MaterialButtom_icon attribute but it seems that you are using Button instead of MaterialButton in your java code. The correct declaration of material button is as:

MaterialButton button = findViewById(R.id.your_material_button_id);

And Not

Button button = findViewById(R.id.your_material_button_id);

By the correct declaration then we have:

这些在Material Button Google参考文档中的一堆不存在的方法是什么?

huangapple
  • 本文由 发表于 2023年7月6日 11:26:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625303.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定