3

I want to set a transparent black color to my textview background color. How can I do it?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
dilaraates
  • 135
  • 1
  • 1
  • 16

4 Answers4

8
android:background="#55000000"

If you use a color with 8 numbers instead of 6, the first two set the opacity. in this case, the opacity is 0x55 which is 85/255 [roughly 33% opacity].

for programatic, you should be able to use the following (where myTextView corresponds to your View)

myTextView.setBackgroundColor(0x55000000);
binary_falcon
  • 302
  • 3
  • 11
3
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true" >
    <shape>
          <gradient 
            android:startColor="#2fDEDEDE"
            android:endColor="#2F000000"
            android:angle="270" />
        <stroke
            android:color="#cbc9c9" />

        <corners
            android:radius="3dp" /> 

        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>
<item>
    <shape>

            <gradient
            android:startColor="@android:color/transparent"
            android:endColor="@android:color/transparent"
            android:angle="270" />

            <stroke
            android:color="#c3c2c2" />

        <corners
            android:radius="4dp" /> 

        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp" />
    </shape>
</item>

usage:==> android:background="@drawable/btn_trans"

if you want to set black color

android:background="#000"
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
0

make a image transparent in photoshop and apply it to textview background... thats it , you have got transparent background to text view

Pranav Sharma
  • 692
  • 2
  • 9
  • 22
0

Set backgroud color as follows

android:background="@android:color/transparent"
Rahmathullah M
  • 2,676
  • 2
  • 27
  • 44