简体   繁体   中英

Android: ListView xml layout not showing background image when scrolled

I have an Activity with a ListView, I set the background image to the view programatically. When I scroll down my list, the background image turns to white ( because my theme is Theme.Light.NoTitleBar).

  1. How can I make it scroll with the blue background intact?
  2. If the above point works, how can I change the text color of ListView to white instead of black?

Normal ListView 普通ListView

Scrolling ListView 滚动ListView

Pressing ListView item 按ListView项

在ListView标记上添加一个属性

android:cacheColorHint="#00000000"// setting as a transparent color
  1. Use the attribute android:cacheColorHint="#000000" in ListView Tag
  2. Regarding make TextView's color black or white, you can refer here to make a custom TextView for your ListView row, The extra work you have to do is just add another attribut inside TextView tag like this

    android:textColor="#FFF" //or #FFFFFF for white

This is due because of an optimization. To remove this, just set the cacheColorHint of your listView to transparent, like this: android:cacheColorHint="#00000000"

Full post here: http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html

You can Wrap that ListView inside on LinearLayout having same background and then remove ListView 's Background that should work fine. :)

Please check this answer. I have got the same issue and it is fixed by putting view = null in adapter side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM