Reputation: 942
How can I get my color and set opaque to it?
int myColor = getResources().getColor(R.color.ColorPrimary);
Upvotes: 4
Views: 2162
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
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
Reputation: 131
setAlpha is applied on views. Get your view and then use .setColor(...)
and .setAlpha(...)
.
Upvotes: 0