我有一个自定义 ListView
,其中每个 row.xml
如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/star_listed"
style="?android:attr/starStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/question_img_cd"
android:focusable="false"/>
<TextView
android:id="@+id/listTitles"
style="@style/ListTitles" />
一切正常,除了当我按下 ListView
上的任意位置时,CheckBox
的背景变为黑色(而不是保持白色)。在我将其背景颜色设置为白色之前,它也发生在我的 TextView
上。
如果我将“CheckBox”背景更改为白色,甚至透明,它就会消失。
有什么建议吗?
最佳答案
我不确定,但这可能会发生,因为您使用了具有透明背景(我不确定)的星号 (?android:attr/starStyle
) 的默认样式属性,并且您会看到底层的黑色行颜色。尝试为行中的父 LinearLayout
设置白色,而不是为行中的每个 View
设置颜色。
关于android - 为什么触摸 ListView 时我的 CheckBox 的背景颜色会改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10649751/