2

I’ve searched and I haven’t found a way to get a certain level of transparency in a colored button while the text of the button is 100% visible.

There has been options to get certain levels of transparency in a button, but the text also becomes transparent and that’s not what I want.

Any pointers?

rene
  • 41,474
  • 78
  • 114
  • 152
camjames
  • 19
  • 3

1 Answers1

0

Do do it in code, you can use:

yourButtonName.getBackground().setAlpha(int alpha)

where alpha is an int between 0 and 255.

Do do it in XML, you would add something like this to your button attributes:

android:background="#8000FF00"

This would yield a 50% opaque green color.

To better understand how we arrive at the code "#8000FF00" , look here.

:)

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
  • Thanks. I'm assuming that this should go in the java code or maybe in styles? – camjames Mar 27 '18 at 03:26
  • Thank you. I went another route as I created a separate button file in the drawable folder. When I attempted to do another drawable folder for the textColor, no matter which color I picked, it just had it as a bright pink color, which was weird. At least the color was solid and didn't fade along with the background color for the button. I decided to get rid of the textColor drawable folder altogether and just put the textColor in the activity_main. – camjames Mar 27 '18 at 12:46
  • @camjames Maybe the color was accidentally transparent and mixing with an underlying color making pink. Anyway... You could still accept my answer even though your original question no longer applies... it might apply for someone else. – Nerdy Bunz Mar 27 '18 at 22:12
  • Ok. I'm new here and I didn't see an accept button. I will look for it. Btw, I was thinking that that was the case, but no matter which color I placed there, it had the same pink. Weird. Thanks for your help though. – camjames Mar 28 '18 at 05:35