如何改变CheckBox的默认图像 [英] How to change default images of CheckBox

查看:138
本文介绍了如何改变CheckBox的默认图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ListView和每一行我有row_item.xml和我吹在code

I am using ListView and for every row I have row_item.xml and I inflate that in code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <CheckBox
        android:id="@+id/chk"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/txtChoice"
        android:textColor="#FF0000"
        android:text="TEST"
        android:layout_toRightOf="@id/chk"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /> 
</RelativeLayout>

如何在被选中更改复选框使用另一个custom_1图像进行检查时,另一custom_2形象?

How to change that checkBox use another custom_1 image when is checked and another custom_2 image when is unchecked ?

推荐答案

绘制对象的 customdrawablecheckbox.xml

<?xml version="1.0" encoding="utf-8"?>
<selector  xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_checked="false" android:drawable="@drawable/yourdrawable1" />
     <item android:state_checked="true" android:drawable="@drawable/yourdrawable2" />
     <item android:drawable="@drawable/yourdrawable1" /> <!-- default state -->
</selector>

yourcheckbox XML:

yourcheckbox xml:

<CheckBox
    android:id="@+id/chk"
    android:button="@drawable/customdrawablecheckbox"
    android:layout_alignParentLeft="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

这篇关于如何改变CheckBox的默认图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆