How to make a ListView transparent in Android?

ぐ巨炮叔叔 提交于 2019-12-17 08:11:49

问题


How to make the ListView transparent in android?

The background android screen image should be visible.


回答1:


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.




回答2:


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




回答3:


  • 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"



回答4:


try this:

list.setCacheColorHint(Color.TRANSPARENT);



回答5:


Add this to make list items stay transparent when pressed:

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



回答6:


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"




回答7:


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/




回答8:


You can use these

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



回答9:


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.




回答10:


try this:

android:cacheColorHint="@null"



回答11:


Check this blog.

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

or

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


来源:https://stackoverflow.com/questions/1377336/how-to-make-a-listview-transparent-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!