I have a layout:
<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>
in my fragment I can set background color in this way:
favorite_color1.setBackgroundColor(color)
A MaterialButton
has a method background
that returns a RippleDrawable
and I saw this question but it doesn't work and it is out of date probably.
How Can I get background color for a MaterialButton
programmatically?