0

I need relative layout background with some transparent for that i used gradient option, But it is affecting text view color also , I gave color of text view is white color but it looks like gray color. Please help me to get out of this issue.

<RelativeLayout
    android:id="@+id/topLayout1"
    android:layout_width="match_parent"
    android:layout_height="210dp"
    android:layout_alignParentTop="true"
    android:foreground="@drawable/image_overlay"
    >

    <RelativeLayout
        android:id="@+id/topLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/preloader_image"
        >
        <TextView
            android:id="@+id/resName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp"
            android:text="Green Way"
            android:textColor="@color/White"
            android:textSize="25sp"
            android:backgroundTint="@color/White"

            />

        <TextView
            android:id="@+id/desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/resName"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:text="@string/items"
            android:textColor="@color/White"
            android:textSize="16sp"
             />

    </RelativeLayout>
</RelativeLayout>

and image overlay code,

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
    android:startColor="#B0000000"
    android:centerColor="#A0000000"
    android:endColor="#00FFFFFF"
    android:angle="270"
    />
  </shape>

<color name="White">#FFFFFF</color>
Saranya Subramanian
  • 417
  • 1
  • 5
  • 19

1 Answers1

0

You can use #83000000 color code for setting transparency and that too in android:background instead of android:background property. Alternatively, you can also use "android:aplha="0.x" where 1 < x < 9, for transparency. Your final code will look like this.

<RelativeLayout android:id="@+id/topLayout1"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_alignParentTop="true"
android:background="#83000000"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/resName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:text="Green Way"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        android:backgroundTint="#FFFFFF" />

    <TextView
        android:id="@+id/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/resName"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="Items"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />
</RelativeLayout>

You should see this ANSWER to know more about transparency. You can use various hex codes to achieve different level of transparency. Like for 50% transparency 80 code is used and color code would be like #80000000. Similary, you can use various codes in the scheme #xx000000.

ankuranurag2
  • 2,300
  • 15
  • 30