【问题标题】:List Item background is changing on scroll列表项背景在滚动时发生变化
【发布时间】:2011-01-25 20:30:15
【问题描述】:

我为 ListView 应用了背景颜色

<style name="CKButtons">
    <item name="android:windowBackground">@color/window_background</item>
</style>

但每次滚动列表时,背景颜色都会变回系统默认值(黑色)。当滚动停止时,颜色会变回@color/window_background

样式应用在AndroidManifest.xml:

<activity android:name=".event.EventList" 
    android:theme="@style/CKButtons"></activity>

我的 ListView 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/android:list"/>
<TextView
    android:id="@+id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/eventlist_no_items"/>
</LinearLayout>

我怎样才能防止这种情况发生?

【问题讨论】:

    标签: xml android listview styles


    【解决方案1】:

    您可以使用ListView 上的属性android:cacheColorHint 设置一个RGB 值,该值应用作列表项被触摸时的背景颜色。

    欲了解更多信息,请参阅:http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html

    【讨论】:

    【解决方案2】:

    我自己已经想通了

    <style name="CKButtons">
        <item name="android:windowBackground">@color/window_background</item>
        <item name="android:listViewStyle">@style/CKListview</item>
    </style>
    
    <style name="CKListview" parent="android:style/Widget.ListView">
        <item name="android:cacheColorHint">@color/window_background</item>
    </style>
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多