创建自定义检查的Andr​​oid箱 [英] Create custom check boxes in android

查看:124
本文介绍了创建自定义检查的Andr​​oid箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序。有哪些要求7复选框,但作为由SDK提供的默认勾选框的大小非常大,需要大量的空间,我试图开发自己定制的复选框的活动。

I have an android application. There is an activity which demands 7 checkboxes but as the size of the default check boxes provided by SDK is very large and takes lots of space, I tried to develop my own customized check boxes.

对于这一点,我已抓获两个图像(选中和未选中),一方面,这切换,即点击选中的点击将其转换为未选中状态,反之亦然。

For this, I have captured two images (checked and unchecked), On click of one it toggles, i.e. on click of checked it converts to unchecked and vice versa.

但我想知道有没有其他的办法做到这一点。

But I want to know is there any other way to do this..

推荐答案

这是通过将一个适当的可绘制的XML文件为您的复选框一点简单的你需要设置相应的图像状态。

It's little simple by placing an appropriate drawable xml file for your checkbox states with corresponding images you need to set.

放置在低于code在绘制名为checkbox.xml

place the below code in drawable named checkbox.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"
          android:drawable="@drawable/star_checked" /> <!-- pressed -->
    <item android:state_checked="false"
          android:drawable="@drawable/star_unchecked" /> <!-- focused -->
     <item android:drawable="@drawable/star_unchecked" />      
</selector>

和你的复选框之上code设置来操作,使用安卓按钮= @绘制/复选框

and on your checkbox set above code to manipulate, by using android:button=@drawable/checkbox"

<CheckBox android:id="@+id/chkFav" android:layout_width="wrap_content"
        android:layout_marginRight="0dp" android:button="@drawable/checkbox"
              android:layout_height="wrap_content" android:clickable="true"/>

这篇关于创建自定义检查的Andr​​oid箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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