Android Transparent TextView?

Viewed 131931

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

15 Answers

This question has many answers, but only a few are easy to understand.

Just to sum it up and make it clear:


The best solution to set a color transparent in XML would be to use:
(by @darvinda)

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

And easiest solution to set it with Java code would be:
(by @Aaron)

setBackgroundColor(Color.TRANSPARENT);

And to explain what the alpha channel ("the transparency of the color") is:

  • Alpha is the transparency of the color
  • Set the Alpha value to 00 (hex) to make any color fully opaque
  • Set the Alpha value to ff (hex) to make it transparent (the color doesn't matter anymore).

So the alpha channel represents the degree of transparency in an alpha-rgb color space. To make something transparent it doesn't matter with rgb-color you use, as long as the "alpha"-color is set to 00.

The values (hex) in an alpha-rgb color space are:
"#aarrggbb" (a=alpha, r=red, g=green b=blue)

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).

setBackgroundColor(Color.TRANSPARENT);

The simplest way

Related