我正在显示一个ListView
。 当我拖动它,整个ListView
被选中与黑色的背景。 我怎样才能删除黑色的背景?
只需在ListView中使用你的xml文件,
android:cacheColorHint="@android:color/transparent"
这可能是因为你有一个自定义的ListView
背景。 当您滚动时,由于其cache color
,整个列表将以黑色突出显示。
将这段代码添加到您的ListView
并再次尝试:
android:cacheColorHint="#00000000"
view.setBackgroundColor(android.R.color.transparent);
应该是view.setBackgroundResource(android.R.color.transparent)导致setBackgroundColor以hex颜色值作为参数。
要么
android:cacheColorHint = "#00000000"
使用这个标签为你的listView。 或者你也可以使用
listview.setCacheColorHint()
以编程方式进行设置。
从为什么我的列表黑色? Android开发者博客上的Android优化 :
要解决此问题,您只需要禁用caching颜色提示优化,如果您使用非纯色背景,或将提示设置为适当的纯色值。 通过使用android:cacheColorHint属性,这可以是代码顶点或者最好来自XML。 要禁用优化,只需使用透明颜色#00000000。 以下屏幕截图显示了在XML布局文件中设置的android:cacheColorHint =“#00000000”的列表:
用这个,
yourList.setCacheColorHint(Color.WHITE);