【问题标题】:Why does the background color of my CheckBox change when ListView is touched?为什么触摸 ListView 时我的 CheckBox 的背景颜色会发生变化?
【发布时间】:2012-05-18 09:07:54
【问题描述】:

我有一个自定义 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 之前也发生过这种情况,直到我将其背景颜色设置为白色。

如果我将“复选框”背景更改为白色,甚至是透明的,它就会消失。

有什么建议吗?

【问题讨论】:

标签: android checkbox android-listview background-color


【解决方案1】:

我不确定,但这可能是因为您使用了具有透明背景(我不确定)的星的默认样式属性(?android:attr/starStyle),并且您看到了底层的黑色行颜色。尝试为行中的父 LinearLayout 设置白色,而不是为行中的每个 View 设置颜色。

【讨论】:

  • 你又来了!我已将其设置为“ListView”,但没有设置为“LinerLayout”。谢谢。就是这样。
【解决方案2】:

您可以在项目资源的样式 xml 文件上设置背景复选框以透明(或)设置列表视图背景颜色!

欢迎!

【讨论】:

  • 嗨@Dinesh,我的问题是关于CheckBox 的颜色,应该在xml 属性上解决。自定义ListView 的逻辑工作正常。
猜你喜欢
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-15
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多