2016-08-15 57 views
-2

我需要从enter image description here 改变复选框enter image description here如何修改这个复选框?

+0

把你的.xml或复选框 – KrishnaJ

+0

的风格我只有正常的复选框您的自定义背景,我不知道该怎么做,这就是为什么我是询问 –

+0

你试过'android:buttonTint =“@ color/CHECK_COLOR”' – KrishnaJ

回答

0

我发现改变刻度线的颜色,你必须把选择:

<?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/checked" /> 
<item android:state_checked="false" android:drawable="@drawable/unchecked" /> 
</selector> 

在XML:

<CheckBox 
    android:id="@+id/cb" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@drawable/your_selector"/> 
+0

可绘制文件? –

+0

您也可以设置颜色代替drawables。 – KrishnaJ

0

创建XML文件

coustom_check_box.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/checked" /> 
     <item android:state_checked="false" android:drawable="@drawable/unchecked" /> 

    </selector> 

在复选框set android:button属性为custom_checkbox_design.xml绘制像 android:button="@drawable/coustom_check_box"

   <CheckBox 
        android:id="@+id/checkBoxCustomized1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Coustom Checkbox" 
        android:checked="true" 
        android:button="@drawable/coustom_check_box" 
        android:textSize="20dp" /> 

图标

enter image description here enter image description here

+0

你能分享添加drawabl文件 –

+0

,但在你的情况下,你使用自己的图标。 –

+0

@EbinFrancis是你的问题解决? –

0

创建d rawable custom_cheackbox:

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

里面添加custom_checkbox android:button="@drawable/custom_cheackbox"

<CheckBox 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:button="@drawable/checkbox_selector" 
    android:text="CheckBox" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="@color/Black" />