android background in xml: tranparency become black not white

5.6k views Asked by At

I make a xml file for android interface. In this xml, there's an expendable items. I want to add background for this xml with tansparency (alpha) but when i add bacground in relative layout with alpha like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:alpha="0.2"
tools:context=".ListGestureActivity" >

that will make background transparency become black not white. In other xml happened like that too. But in other xml i tried to do this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".HintGestureActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:alpha="0.3"
    android:background="@drawable/background"
    />

it worked. But in xml with expendable items didn't work. Do you any suggestion?

2

There are 2 answers

2
AndroidHacker On

U can do something like this

android:background="#00564678"

For Ex:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:alpha="0.3"
    android:background="#00564678"
    />
2
Zankhna On

By default it takes black color as your background color and after that, if you apply transparency then you will not get desired output.Therefore, first you need to set some background color after that apply alpha on that. Try this :

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:alpha="0.2"
tools:context=".ListGestureActivity" >