0

I have a Textview with a background drawable. I want to add the alpha option but I want to set it only in the background and not affect the opacity of the text itself.

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|start"
    android:layout_margin="4dp"
    android:alpha="0.25"
    android:background="@drawable/primary_background"
    android:padding="2dp"
    android:text="Unknown"
    android:textColor="@color/colorWhite"
    android:textSize="12sp" />

and primary background

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="@color/colorPrimaryDark" >
    </solid>
    <corners android:radius="25dp" />
</shape>

But the transparency goes to the text also. How can I do that?

AmrDeveloper
  • 3,826
  • 1
  • 21
  • 30
james04
  • 1,580
  • 2
  • 20
  • 46

1 Answers1

0

NO need to provide alpha to text. in your case you just pass the required solid color to your drawable.

 <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top|start"
            android:layout_margin="4dp"
            android:background="@drawable/primary_background"
            android:padding="2dp"
            android:text="Unknown"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />
Rajshekhar
  • 571
  • 5
  • 9