Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a colour by referencing a colour and adding transparency information? [duplicate]

This is just a minor question to speed things up a little bit, but I'm wondering if I can reference other colours and add additional information in my XML file.

I know that this code works:

<color name="primary1">#708FA3</color>
<color name="primary1_transparent">@color/primary1</color>

But I'm wondering is there a way to add a level of transparency to primary1_transparent? Either by concatenation in the assignment or afterwards. Something like this for example:

<color name="primary1">#708FA3</color>
<color name="primary1_transparent">#55 + @color/primary1</color>

I know that looks horrible and doesn't work, but hopefully it makes it clear what I'm looking to do.

Obviously the time saving on this isn't significant so an awkward workaround isn't going to help much but it seems like a possibly existing feature/hack I can't find.

like image 957
SuperBiasedMan Avatar asked Nov 09 '22 21:11

SuperBiasedMan


1 Answers

You can add transparency via XML itself by adding the following line to your view:

 android:alpha="0.25" 

You can adjust alpha value to increase or decrease the amount of transparency.

Example:

<View
    android:id="@+id/view1"
    android:layout_width="wrap_content"
    android:layout_height="150dp"
    android:alpha="0.25"
    android:background="@android:color/black"
    android:layout_alignParentLeft="true" />

This code made the Black background translucent: This

like image 136
Tushar Gogna Avatar answered Nov 14 '22 22:11

Tushar Gogna