Android学习|控件_Button
StateListDrawable
StateListDrawable是Drawable资源的一种,可以根据不同的状态,设置不同的图片效果,关键节点selector,我们只需要将Button的background属性设置为该drawable资源即可轻松实现,按下按钮时不同的按钮颜色或背景
button继承TextView,所以TextView有的Button都有
基础属性
1,drawable:引用的Drawable位图
2.state_focused:是否获得焦点
3.state_pressed:控件是否被按下
4.state_enabled:控件是否可用
5.state selected:控件是否被选择,针对有滚轮的情况
6.state_checked:控件是否被勾选
7.state_checkable:控件可否被勾选,eg:checkbox
8.state-window_focused:是否获得窗口焦点
9.state_active:控件是否处于活动状态,eg:slidingTab
10.state-single:控件包含多个子控件时,确定是否只显示一个子控件
11.state first:控件包含多个子控件时,确定第一个子控件是否处于显示状态12.state_middle:控件包含多个子控件时,确定中间一个子控件是否处于显示状态
13.state_last:控件包含多个子控件时,确定最后一个子控件是否处于显示状态
基础实例
1.btton图标设置及变化
新建Model,xml中如下定义button
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="我是按钮"
android:background="@drawable/btn_selector"
>
</Button>
</LinearLayout>
上述的button背景使用了外部导入内容,导入内容为drawable中新建btn_selector.xml,内容如下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android=