换言之,就像Android Button一样,基于布局文件,把LinearLayout做成一个可以在用户交互触摸点击时候背景颜色有所改变的控件。
具体方法:
(1)在LinearLayout属性中写:
android:background="@drawable/selector"
(2)在drawable目录下新建selector.xml文件,设置状态和焦点事件响应的背景。
(3)如果selector.xml文引用了自定义颜色,在values目录下新建color.xml,写颜色的属性值。
例如:
activity_main.xml:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/selector"
android:clickable="true"
android:orientation="vertical" >
activity_main.xml中设置了background,在drawable下新建selector.xml:
selector.xml中又引用了自定义颜色,那么就需要在values目录下建立color.xml:
#ff5654
#ddff5654