Android - 视图点击效果
jopen
9年前
视图点击修改背景.
按压时更换背景, 抬起时恢复背景, 依赖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>
来自: http://blog.csdn.net//caroline_wendy/article/details/48469913