Android - 视图点击效果

来源:互联网 发布:ubuntu的samba服务器 编辑:程序博客网 时间:2024/06/01 09:18

视图点击修改背景.
按压时更换背景, 抬起时恢复背景, 依赖state_pressed.
登陆成功后禁止点击, 并更换背景, 依赖state_enabled.

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@android:color/transparent"          android:state_pressed="true"/>    <item android:drawable="@android:color/transparent"          android:state_enabled="false"/>    <item android:drawable="@color/white"/></selector>

系统默认点击的闪烁效果, 版本5.0以上支持.
android:background="?android:attr/selectableItemBackground"

Code

<selector xmlns:android="http://schemas.android.com/apk/res/android"          android:exitFadeDuration="@android:integer/config_mediumAnimTime">    <item android:drawable="@color/transparent"          android:state_window_focused="false"/>    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->    <item android:drawable="@drawable/list_selector_background_disabled"           android:state_enabled="false"           android:state_focused="true"           android:state_pressed="true"/>    <item android:drawable="@drawable/list_selector_background_disabled"           android:state_enabled="false"           android:state_focused="true"/>    <item android:drawable="@drawable/list_selector_background_transition"           android:state_focused="true"           android:state_pressed="true"/>    <item android:drawable="@drawable/list_selector_background_transition"           android:state_focused="false"           android:state_pressed="true"/>    <item android:drawable="@drawable/list_selector_background_focused"           android:state_focused="true"/>    <item android:drawable="@color/transparent"/></selector>
1 0