標籤:mystra android 視圖點擊效果
視圖點擊修改背景.
按壓時更換背景, 抬起時恢複背景, 依賴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>
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Android - 視圖點擊效果