1

我有一个列表视图。当用户选择特定项目时,复选框颜色变为绿色...我希望复选框的颜色应变为橙色或红色..这怎么可能?

4

2 回答 2

1
<CheckBox android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="new checkbox"
 android:background="@drawable/checkbox_background" 
 android:button="@drawable/checkbox" />

@drawable/checkbox 如下:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" android:state_focused="true"
  android:drawable="@drawable/checkbox_on_background_focus_red" />
 <item android:state_checked="false" android:state_focused="true"
  android:drawable="@drawable/checkbox_off_background_focus_orange" />
 <item android:state_checked="false"
  android:drawable="@drawable/checkbox_off_background" />
 <item android:state_checked="true"
  android:drawable="@drawable/checkbox_on_background" />
</selector>

checkbox_on_background_focus_red、checkbox_off_background_focus_orang、checkbox_off_background 和 checkbox_on_background 是您的 drawble 文件夹中所需的复选框图像

于 2012-06-12T10:59:20.803 回答
0
1- implement the OncheckedLinstener and notify data set changed to list 
2- put check in getview if(chk.isChecked()){//setBG color green }else {red} 
2- either set the selector to checkbox or change the BG color of chk box in if else in getview

如果想优化然后

使用标签中的复选框设置列表项的位置,在 OncheckedLinstener 中,您将获得视图,只需从选项卡中的视图中获取位置,并使用 getFirstVisiblePosition 和 getLastVisiblePosition、getChildAt(int index) 并更改它。

于 2012-06-12T11:01:59.023 回答