Set alpha for color resource basing on another color

572 Views Asked by At

If I have <color name="primary">#112233</color>,

  1. Can I set android:background attribute to primary, but adding opacity? For example, adding #40000000 to get #40112233.
  2. Can I make another color, basing on primary, but adding opacity? For example, make something like <color name="primary_semitransparent">#40000000 + @color/primary</color> to produce @color/primary_semitransparent with value of #40112233
1

There are 1 best solutions below

0
On

This isn't an exact duplicate, but this question gets answered in How to create a transparent Color Resource? pretty well.

To answer the question here as well:
If you use 8 characters for a color then the first 2 will be used for opacity. So to greate a half transparent "primary" use:
<color name="primary">#CC112233< /color>.