Tamaghna M
Tamaghna M

Reputation: 845

How to make a ListView transparent in Android?

How to make the ListView transparent in android?

The background android screen image should be visible.

Upvotes: 64

Views: 91507

Answers (11)

Jacky
Jacky

Reputation: 1905

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

Upvotes: 60

Avinash Jain
Avinash Jain

Reputation: 271

Check this blog.

[http://aboutyusata.blogspot.in/2013/10/how-to-make-listview-with-transparent.html][1]

or

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

Upvotes: 0

Kailas
Kailas

Reputation: 3241

You can use these

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

Upvotes: 3

Aaron
Aaron

Reputation: 2080

If you want to use partial transparency, this would help you while setting your color codes.

2 hex characters can be appended to any hex color code. The first 2 characters in an 8-digit hex color code represents its opacity in Android.

The 2 hex characters can range from 00 to FF. For example-

  • Normal opaque black hex- "#000000"
  • Fully transparent black- "#00000000"
  • Fully opaque black- "#FF000000"
  • 50% transparent black- "#80000000"

This way you can change any color to any level of transparency.

Source- http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/

Upvotes: 3

romanzah
romanzah

Reputation: 21

try this:

android:cacheColorHint="@null"

Upvotes: 1

Denis
Denis

Reputation: 41

Add this to make list items stay transparent when pressed:

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

Upvotes: 4

bhatt4982
bhatt4982

Reputation: 8054

  • How to make the ListView transparent in android?

As Jacky mentioned, setting attributes for list view will do the job.

android:background="#00000000" 
android:cacheColorHint="#00000000"
  • The background android screen image should be visible.

In Android manifest file add following attribute to activity.

android:theme="@android:style/Theme.Dialog"

Upvotes: 13

nikki
nikki

Reputation: 3228

try this:

list.setCacheColorHint(Color.TRANSPARENT);

Upvotes: 4

mxk
mxk

Reputation: 43544

You should use the more verbose

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

Updated with Jacky's response. I originally merely meant to add to his answer, since he was using a plain hex color in the sample.

Upvotes: 123

XMight
XMight

Reputation: 2121

The answers above will work, but there is a chance that when you'll scroll the listView, it will darken, like in this case: android-listview problem with transparent cells

To solve the issue, you can use the cacheColorHint as mentioned above, but if you add the ListView dynamically (from code, not xml), then this will not work. You are forced to declare the ListView in XML, dunno if this is a bug or something else.

Upvotes: 1

cornbread ninja
cornbread ninja

Reputation: 427

This article helps explain the nuances of ListView in conjunction with a custom background - http://developer.android.com/resources/articles/listview-backgrounds.html

tl;dr - put this in the offending ListView's xml somewhere:

android:cacheColorHint="#00000000"

Upvotes: 4

Related Questions