Java – focus on lost animation on Android / ice cream sandwich

On my tablet, whenever I put my finger on something that can be clicked (such as a menu item), it will be highlighted in light blue When you pull your finger apart, there will be a small fading

Who knows where this animation / color is in the SDK? I want to play this animation programmatically on the button I own

Solution

Use the Android: exitfadeduration property in the background statelistdrawable of the button:

<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="100">
    <!-- Non focused states -->
    <item android:drawable="@drawable/button_normal" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
    <item android:drawable="@drawable/button_normal" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
    <!-- Focused states -->
    <item android:drawable="@drawable/button_focused" android:state_focused="true" android:state_pressed="false" android:state_selected="false" />
    <item android:drawable="@drawable/button_focused" android:state_focused="true" android:state_pressed="false" android:state_selected="true" />
    <!-- Pressed -->
    <item android:drawable="@drawable/button_pressed" android:state_pressed="true" />
</selector>

Note that this applies to Android > = 3.0 (API level 11)

File: http://developer.android.com/reference/android/R.attr.html#exitFadeDuration

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>