Custom selector fade animations

So you want to add a little flare between your custom selector states on Android? As of HoneyComb 3.0+ this is pretty easy.


Take home_tile_background_selector.xml here:

<?xml version="1.0" encoding="utf-8"?
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">

  <item android:drawable="@drawable/home_tile_background_pressed" android:state_selected="true"/>
  <item android:drawable="@drawable/home_tile_background_pressed" android:state_pressed="true"/>
  <item android:drawable="@drawable/home_tile_background_pressed" android:state_focused="true"/>
  <item android:drawable="@drawable/home_tile_background_default"/>
</selector>

The line of code android:exitFadeDuration="@android:integer/config_mediumAnimTime" above is the key, this will enable those lovely fade away selectors.
Android Provides a few time periods, so have play and enjoy :)

comments powered by Disqus