In my application, I apply the transparent background to my ListView's CustomListItem at runtime. For that I use, convertView.setBackgroundColor(android.R.color.transparent);. It works and shows transparency. But that is not fully transparent as there is some kind of shade to the background. I also tried putting my own transparent color with the values #80000000 and #00000000 but the result is worse. What can I do to get the fully transparent color?
Asked
Active
Viewed 3.1k times
11
Rajkiran
- 15,333
- 24
- 73
- 110
5 Answers
27
Set this attribute to your listview in xml file
android:background="@android:color/transparent"
and also apply the transparent background to your ListView's CustomListItem at runtime. For that you have use,
convertView.setBackgroundColor(Color.TRANSPARENT);
Thanks
Kumar Bibek
- 8,935
- 2
- 38
- 67
Zumbarlal Saindane
- 1,179
- 11
- 23
-
1No man. Read my question. `convertView.setBackgroundColor(android.R.color.transparent);` was not working. Read @antonyt answer. It worked. – Rajkiran Apr 03 '12 at 07:27
25
android.R.color.transparent is a resource id (referring to a transparent color definition) - View.setBackgroundColor(int) expects an actual int color.
Use View.setBackgroundResource(int) instead, which will load the actual color from resources.
antonyt
- 21,773
- 9
- 68
- 69
-
1worked, but why it's not working the obvious way is still a mystery. – halxinate Apr 08 '13 at 19:16
5
convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));
OR
convertView.setBackgroundColor(Color.parseColor("#00000000"));
Vinothkumar Arputharaj
- 4,459
- 4
- 26
- 36
4
Use this from now in your xml's files when you want transparency in your views:
android:background="@null"
You are going to get a better performance.
danigonlinea
- 1,103
- 1
- 14
- 19