如何申请自定义图像中的Andr​​oid到复选框自定义、复选框、图像、Andr

2023-09-05 08:20:56 作者:回眸一笑抹倾城

我想要应用自定义图像中的Andr​​oid到复选框,为了这个,我创建一个 check_custom.xml 文件中,我定义自定义图像的复选框不同状态这样的:

I'm trying to apply custom image to checkbox in android, for this I create an check_custom.xml file in which I define custom image for different states of check box like:

<item android:state_checked="true" 
      android:drawable="@drawable/btn_check_on" /> <!-- checked --> 
<item android:state_checked="false" 
      android:drawable="@drawable/btn_check_off" /> <!-- unchecked --> 
<item android:state_focused="true"
      android:drawable="@drawable/btn_check_onfocus" />    <!--on focus--> 
<item android:drawable="@drawable/btn_check_off" /> <!-- default --> 

在检查,焦点和选中的三种状态三种不同的图像, 然后我将这个XML文件的复选框的背景属性,但我没有得到需要的结果,这种技术应用自定义图像,以及默认设置情况下的图像。

Three different images on three states on checked,on focus and on unchecked, and then I assign this xml file to background attribute of check boxes,but I'm not getting required result, this technique apply the custom image as well as default image both.

推荐答案

萨尔曼,设置安卓按钮而不是安卓背景。另请参见自定义复选框形象的Andr​​oid

Salman, set android:button instead of android:background. See also Custom checkbox image android