在我的应用程序中,我在运行时将透明背景应用于ListView
的CustomListItem。为此,我使用convertView.setBackgroundColor(android.R.color.transparent);
。它起作用并显示透明度。但这并不完全透明,因为背景有某种阴影。我还尝试使用值#80000000
和#00000000
创建自己的透明颜色,但结果更糟。我该怎么做才能获得完全透明的颜色?
答案 0 :(得分:24)
将此属性设置为xml文件中的列表视图
android:background="@android:color/transparent"
并在运行时将透明背景应用于ListView的CustomListItem。 为此你有用,
convertView.setBackgroundColor(Color.TRANSPARENT);
由于
答案 1 :(得分:23)
android.R.color.transparent
是资源ID(指透明颜色定义) - View.setBackgroundColor(int)
需要实际的int颜色。
改为使用View.setBackgroundResource(int),这将从资源加载实际颜色。
答案 2 :(得分:5)
convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));
OR
convertView.setBackgroundColor(Color.parseColor("#00000000"));
答案 3 :(得分:4)
如果您希望在视图中使用透明度,请在xml的文件中使用此功能:
android:background="@null"
您将获得更好的表现。
答案 4 :(得分:1)
尝试:
convertView.setBackgroundColor(Color.argb(0, 0, 0, 0));