I have a simple selector for my ListView
The modern way (since api 21) of doing it with example:
<?xml version="1.0" encoding="utf-8"?>
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/checked"
android:drawable="@drawable/check_box_on"
app:check="true" /> <!-- this is custom state. You can use android:state_checked="true"-->
<item
android:id="@+id/unchecked"
android:drawable="@drawable/check_box_off"
app:check="false" />
<transition
android:drawable="@drawable/toggle_checkbox_unchecked_checked"
android:fromId="@+id/unchecked"
android:toId="@+id/checked" />
<transition
android:drawable="@drawable/toggle_checkbox_checked_unchecked"
android:fromId="@+id/checked"
android:toId="@+id/unchecked" />
</animated-selector>
documentation for animated-selector: link
where transition drawable is for example this:
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="@drawable/check_box_on">
<target android:name="check_box_on_path">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/decelerate_cubic"
android:propertyName="trimPathEnd"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType" />
</aapt:attr>
</target>
</animated-vector>
documentation for animated-vector: link
Is it the fade you want?
I guess it would be the same as how a textSwitcher works, maybe you want to change it to a ViewSwitcher instead, the fade is done pro-grammatically
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher1.setInAnimation(in);
mSwitcher1.setOutAnimation(out);
I guess TransitionDrawable could help you to accomplish this.
You can check the answer here: Animate change of view background color on Android
Added in api 21 "StateListAnimator"
http://developer.android.com/reference/android/animation/StateListAnimator.html
I know this is an old question but this may help future people looking to do this.