
借助状态列表图形StateListDrawable,分别定义已选中时候的“开”图形,以及未选中时候的“关”图形。
状态列表图形的XML文件如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/switch_on"/> <item android:drawable="@drawable/switch_off"/></selector>
然后把CheckBox控件的background属性设置为该状态图形。
下面是山寨后的开关按钮效果图。

========================================================================================

最低0.47元/天 解锁文章
4901

被折叠的 条评论
为什么被折叠?



