I need to style ListView and can't figure out why It turns to black background when scroll.. I have ListView inside LinearLayout and that layout has Background set to image.
This is what I have for ListView:
<style name="MyListView" parent="@android:style/Widget.ListView">
<item name="android:listSelector">@drawable/selector_list_item</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_list_item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80ffffff" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80808080" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
When I apply MyListView style I don't see much happening. When I click on item - yes, I see gradient. When ListView stable - I see background as it should be from parent layout. When I scroll - I see black background, it's erasing parent's background. And I would be fine with that if I knew how to set it with something else..
Use the following property in the xml of listView:
android:cacheColorHint="@android:color/transparent"
Try this line of code in the xml of your listview:
android:listSelector="@android:color/transparent"
If you require transparent ListView
in a PreferenceActivity
, try using a theme with
<resources>
<style name="MyPreferencesTheme">
<item name="android:scrollingCache">false</item>
</style>
</resources>
And put the theme in your AndroidManifest.xml
<activity
android:name="YourActivity"
android:theme="@style/MyPreferencesTheme">
</activity>
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.