— Android, XML, Colors, UI Design — 1 min read
Before diving into transparency, let's quickly recap the color formats used in Android XML:
To create a transparent color in Android XML, you'll use the ARGB format. The alpha channel determines the opacity, ranging from 00 (fully transparent) to FF (fully opaque).
Basic Syntax:
1#AARRGGBB
Example:
1<color name="transparent_red">#80FF0000</color>
This defines a red color with 50% opacity (80 in hexadecimal).
You can apply transparent colors to various XML elements, such as:
1<LinearLayout2 android:layout_width="match_parent"3 android:layout_height="match_parent"4 android:background="#80FFFFFF" />
1<TextView2 android:layout_width="wrap_content"3 android:layout_height="wrap_content"4 android:text="Transparent Text"5 android:textColor="#80000000" />
1<shape xmlns:android="http://schemas.android.com/apk/res/android"2 android:shape="rectangle">3 <solid android:color="#80FF00FF" />4</shape>
@android:color/transparent
For complete transparency, you can use the predefined color @android:color/transparent
:
1<View2 android:layout_width="match_parent"3 android:layout_height="match_parent"4 android:background="@android:color/transparent" />
#80FF0000
is 50% opaque.