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

xiaoxiao2021-02-27  167

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">
转载请注明原文地址: https://www.6miu.com/read-13371.html

最新回复(0)