`
staroflife
  • 浏览: 20616 次
社区版块
存档分类
最新评论

android 自定义 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_pressed="true"
        android:drawable="@drawable/focused"/>
  <item android:state_checked="false" android:state_pressed="true"
        android:drawable="@drawable/normal"/>
  <item android:state_checked="false" android:drawable="@drawable/normal"/>
  <item android:state_checked="true" android:drawable="@drawable/focused"/>
</selector>

state_checked选中状态state_pressed按下状态
即分别设置checkbox选中和没选中时按下和没按下时显示的图片。
应用到checkbox与button不同,并不是设置background属性,而是设置style属性,
所以我们要写一个style。
strings.xml写一个style.
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox</item>
应用到checkbox:
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" style="@style/MyCheckBox"/>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics