9.4.1 使用StateListDrawable资源

更新于 2026年10月10日 版权声明
9.4.1 使用StateListDrawable资源

在Android应用程序中,StateListDrawable能够组织多个Drawable对象。当将StateListDrawable作为目标组件的背景或前景图像时,通过StateListDrawable对象显示的Drawable对象会随目标组件状态的改变而自动切换。

在Android应用程序中,定义StateListDrawable对象的XML文件的根元素是<selector.../>在该元素中可以包含多个<item.../>元素,可以指定如下的属性。

■ android:color或android:drawable:指定颜色或Drawable对象。

■ android:state_xxx:指定一个特定状态。(https://www.daowen.com)

具体语法格式如下。

图示

StateListDrawable支持的状态信息的具体说明见表9-2

表9-2 StateListDrawable支持的状态

图示

↑上一章 ↓下一章
关注公众号获取验证码
复制内容需要验证码(7.99元/天)