[android] Android Transparent TextView?

Simply, how to make a TextView transparent? (Not full transparency)

I searched the docs and the StackNetwork and couldn't find it? I guess there is something like this.

Thanks.

UPDATE

This is the XML code:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:background="@drawable/background">

    <ImageView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/header"
    android:src="@drawable/logo1"
    />
    <ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:paddingRight="5dp"
    android:scrollbarStyle="outsideOverlay"
    android:cacheColorHint="#00000000" />


    <TextView
    android:id="@+id/footer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="25sp"
    android:singleLine="true"
    android:background="#07000000"
    android:textColor="#FFFFFF"
    android:text="rrrrr" />

 </LinearLayout>

I want the footer TextView to be transparent so that the ListView items can be seen while scrolling

This question is related to android transparency transparent textview

The answer is


Use this:

android:background="@android:color/transparent"

To set programmatically:

setBackgroundColor(Color.TRANSPARENT);

For me, I also had to set it to Color.TRANSPARENT on the parent layout.


Everyone is answering correctly about the transparency but not listening to what the guy needs in regards to the list scrolling behind the footer.

You need to make the footer part of your ListView. At the moment the list won't scroll behind because the layout of the ListView does not go behind the footer view with the transparency. Make a RelativeLayout and position the transparency at the bottom.


If you are looking for something like the text view on the image on the pulse app do this

 android:background="#88000000"
android:textColor="#ffffff"

Try setting android:background="#00000000" in TextView. Setting alpha of colour 00 will make the background transparent.

I haven't tried this, but it should work.


In case someone wants to do this in the programming way! Do the following: Update the color file in your values folder with this.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00ffffff</color> <!--This is the transparency line-->
</resources>

then call the transparency programitically

your_textview.setBackgroundResource(R.color.transparent);

Hi Please try with the below color code as textview's background.

android:background="#20535252"


try to set the transparency with the android-studio designer in activity_main.xml. If you want it to be transparent, write it for example like this for white: White: #FFFFFF, with 50% transparency: #80FFFFFF This is for Kotlin tho, not sure if that will work the same way for basic android (java).


<TextView android:alpha="0.3" ..., for example.


setBackgroundColor(Color.TRANSPARENT);

The simplest way


Below code for black:-

<color name="black">#000000</color>

Now if i want to use opacity than you can use below code :-

 <color name="black">#99000000</color> 

and below for opacity code:-

Hex Opacity Values

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00

refer Understanding colors on Android (six characters)


Although this answer is very late but might help other developer so I'm posting it here.

Answers above showing only how to set transparent background of TextView. We can achieve transparent Textview backcgorund in two way:

  1. By setting opacity code such as #88000000 in android:background attribute
  2. By setting android:alpha="0.5" attribute to TextView

Second approach is better because it gives flexibility to set background with different color and then setting setting opacity to widget using android:alpha="0.2"

Example

<TextView
        android:id="@+id/tv_name"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:alpha="0.3"
        android:textColor="@color/white"
        android:textStyle="bold"/>

See the Android Color resource documentation for reference.

Basically you have the option to set the transparency (opacity) and the color either directly in the layout or using resources references.

The hex value that you set it to is composed of 3 to 4 parts:

  • Alpha (opacity), i'll refer to that as aa

  • Red, i'll refer to it as rr

  • Green, i'll refer to it as gg

  • Blue, i'll refer to it as bb

Without an alpha (transparency) value:

android:background="#rrggbb"

or as resource:

<color name="my_color">#rrggbb</color>

With an alpha (transparency) value:

android:background="#aarrggbb"

or as resource:

<color name="my_color">#aarrggbb</color>

The alpha value for full transparency is 00 and the alpha value for no transparency is FF.

See full range of hex values below:

100% — FF
 95% — F2
 90% — E6
 85% — D9
 80% — CC
 75% — BF
 70% — B3
 65% — A6
 60% — 99
 55% — 8C
 50% — 80
 45% — 73
 40% — 66
 35% — 59
 30% — 4D
 25% — 40
 20% — 33
 15% — 26
 10% — 1A
  5% — 0D
  0% — 00

You can experiment with values in between those.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to transparency

How can I produce an effect similar to the iOS 7 blur view? How to export plots from matplotlib with transparent background? Hex transparency in colors Setting transparent images background in IrfanView How to make a background 20% transparent on Android How to make graphics with transparent background in R using ggplot2? Android Transparent TextView? SVG fill color transparency / alpha? Understanding colors on Android (six characters) How can I make an image transparent on Android?

Examples related to transparent

How to present a modal atop the current view in Swift How to make div background color transparent in CSS How can I make my website's background transparent without making the content (images & text) transparent too? Android Transparent TextView? PPT to PNG with transparent background Android WebView style background-color:transparent ignored on android 2.2 How to set transparent background for Image Button in code? Transparent background on winforms? How to have a transparent ImageButton: Android How do I create a transparent Activity on Android?

Examples related to textview

Kotlin: How to get and set a text to TextView in Android using Kotlin? How to set a ripple effect on textview or imageview on Android? The specified child already has a parent. You must call removeView() on the child's parent first (Android) Android: Creating a Circular TextView? android on Text Change Listener Android - Set text to TextView Placing a textview on top of imageview in android Rounded corner for textview in android Different font size of strings in the same TextView Auto-fit TextView for Android