【发布时间】:2020-09-23 05:33:01
【问题描述】:
我有一个布局:
<com.google.android.material.button.MaterialButtonToggleGroup
...
app:checkedButton="@+id/favorite_color1"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="@+id/favorite_color1"
... />
<com.google.android.material.button.MaterialButton
android:id="@+id/favorite_color2"
... />
</com.google.android.material.button.MaterialButtonToggleGroup>
在我的片段中,我可以通过这种方式设置背景颜色:
favorite_color1.setBackgroundColor(color)
MaterialButton 有一个方法 background,它返回一个 RippleDrawable,我看到了 this question,但它不起作用,而且可能已经过时了。
如何以编程方式获取 MaterialButton 的背景颜色?
【问题讨论】:
标签: android kotlin android-button material-components materialbutton