Home » Android » listview – android.R.color.transparent not fully transparent

listview – android.R.color.transparent not fully transparent

Posted by: admin May 14, 2020 Leave a comment

Questions:

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?

How to&Answers:

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.

Answer:

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

Answer:

convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));

OR

convertView.setBackgroundColor(Color.parseColor("#00000000"));

Answer:

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.

Answer:

Try:

convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));