Material-components-android: Setting backgroundTint on MaterialButton and keeping/setting disabled state

Created on 26 Jul 2018  路  2Comments  路  Source: material-components/material-components-android

Setting backgroundTint to a Material button changes the background for both enabled and disabled states.

Enabled button after adding tint:
Enabled button after adding tint

Disabled button after adding tint:
Disabled button after adding tint
Disabled button without adding tint:
Disabled button without adding tint

Setting background tint to a state list drawable doesn't work either. Additionally, when set to a state list, it ignores the backgroundTintMode completely.

Is there another way of setting button style for the disabled state that I'm missing, or is this just not supported?

Most helpful comment

Hi Aditya!

The correct way to set this would be to set a color state list to the backgroundTint attribute. The color state list should look something like: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/button/res/color/mtrl_btn_bg_color_selector.xml

Was the state list you set similar to that?

All 2 comments

Hi Aditya!

The correct way to set this would be to set a color state list to the backgroundTint attribute. The color state list should look something like: https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/button/res/color/mtrl_btn_bg_color_selector.xml

Was the state list you set similar to that?

Thanks Gautham!

That worked. The problem was with my state list. I was setting a colour for state enabled=false, and then a fall back colour for the default enabled state. It appears I had to do the opposite.

Cheers!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ataulm picture ataulm  路  3Comments

ahmaducg picture ahmaducg  路  3Comments

JakeWharton picture JakeWharton  路  3Comments

gabrielemariotti picture gabrielemariotti  路  3Comments

Mirmuhsin picture Mirmuhsin  路  3Comments