Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting opaque to custom color in android (setAlpha)

Tags:

java

android

How can I get my color and set opaque to it?

int myColor = getResources().getColor(R.color.ColorPrimary);
like image 338
Zhambul Avatar asked Oct 25 '25 03:10

Zhambul


1 Answers

You can use ColorUtils.setAlphaComponent to create a new color value with the same RGB but different alpha. The alpha value needs be from 0 - 255 so it would look something like this:

int color = getResources().getColor(R.color.ColorPrimary);
int color50percent = ColorUtils.setAlphaComponent(color, 128);
like image 121
queencodemonkey Avatar answered Oct 27 '25 03:10

queencodemonkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!