Zhambul
Zhambul

Reputation: 942

Setting opaque to custom color in android (setAlpha)

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

int myColor = getResources().getColor(R.color.ColorPrimary);

Upvotes: 4

Views: 2162

Answers (3)

queencodemonkey
queencodemonkey

Reputation: 441

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);

Upvotes: 8

Mochamad Taufik Hidayat
Mochamad Taufik Hidayat

Reputation: 1314

this is example color black alpha 65

 <color name="ColorPrimary">#A6000000</color>

if you want change opacity just change 2 number in front
hope it help

Upvotes: 1

Sahar Avr
Sahar Avr

Reputation: 131

setAlpha is applied on views. Get your view and then use .setColor(...) and .setAlpha(...) .

Upvotes: 0

Related Questions