Android笔记(1)layout类似按钮的按下状态

来源:互联网 发布:如何判断域名被劫持 编辑:程序博客网 时间:2024/05/16 17:52

1.在drawable文件夹中新建xml文件:selector_press
selector_press内容:

<?xml version="1.0" encoding="utf-8"?><!-- 这个是用于控制按钮组背景的文件 --><selector xmlns:android="http://schemas.android.com/apk/res/android">    <!-- **点击时效果**********背景引用的资源*************************是否获得焦点*********************是否按下******* -->    <item android:drawable="@drawable/press_false" android:state_focused="true" android:state_pressed="false"/>    <item android:drawable="@drawable/press_true" android:state_focused="true" android:state_pressed="true"/>    <item android:drawable="@drawable/press_true" android:state_focused="false" android:state_pressed="true"/>    <!-- **************没有任何操作时显示的背景************** -->    <item android:drawable="@drawable/press_false"></item></selector>

2.布局中:

<LinearLayout        android:id="@+id/layout31"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:orientation="horizontal"        android:gravity="center"        android:background="@drawable/selector_press">
阅读全文
1 0