1

Okay... I tried asking this before, but I dont think I explained it well...

I have a button in Android. The button's default color is #999999 (Holo Light), with it's opacity (I think its 40%), on my background color, it ends up calculating to #575757. The background is #303030.

I would like to apply a BackgroundTint to this button. The color I am applying as the tint is #F68800. However, when I apply this tint, the color of the button does not show as #F68800, it instead calculates to #7c501a. I assume this has to do with the Holo Light button being slightly transparent...

What can I do to get the button's final color to show up as #F68800?

I have tried using android:backgroundTintMode="src_over", but that ends up ignoring the style of the button and the 9 patch.

Jason Axelrod
  • 7,155
  • 10
  • 50
  • 78

1 Answers1

1

As you suspect, the original alpha is your problem. You need it to be ignored in order to get your "clear" tint color. However, ignoring the original alpha also means that you lose the shape/style that the button gets from its 9-patch (as you've already noticed).

Naturally, this makes for an impossible situation -- you cannot both ignore and use the original alpha.

If this is really important, I think your best bet may be to just copy the original 9-patch into your project (don't forget all the dpi variants and various states), make the main button area an opaque white, and make your tinted buttons use that background instead.

The easier alternative is to switch to the Material themes (perhaps the support library version in order to get backwards compatibility). The support library also enables backgroundTint on older Android versions.

Community
  • 1
  • 1
Snild Dolkow
  • 6,669
  • 3
  • 20
  • 32