Android用户界面实用技巧
1. CheckBox及其他可勾选控件
许多实现了 Checkable 接口的小部件,如 CheckBox 和 CompoundButton 的其他子类,改变状态的机制略有不同。在这些情况下,背景与状态无关,要自定义表示“已勾选”状态的 Drawable ,可通过另一个名为 button 的属性实现。在XML中,使用 android:button 属性;在代码中,使用 CompoundButton.setButtonDrawable() 方法。
以下是一个示例,在 res/drawable/ 目录下定义了一个 check_states.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/disabled" />
<item android:state_checked="true" android:drawable="@drawable/checked" />
超级会员免费看
订阅专栏 解锁全文
1689

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



