How i can animate background of Image Button in Android with StateListAnimator?

Viewed 206

I want to change color of back icon in ImageButton using sateListAnimator :ImageButton

Image button xml:

<ImageButton
    android:id="@+id/back_btn"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_back"
    android:backgroundTint="@color/colorWhite"
    android:stateListAnimator="@animator/color_animation_btn" />

color_animation_btn xml:

<item android:state_pressed="true">
    <set>
        <objectAnimator
            android:duration="100"
            android:propertyName="backgroundTint"
            android:valueTo="@color/colorBlack"
            android:valueType="colorType"
             />
    </set>
</item>

But this code isn't working: backgroundTint of button isn't changing, but if I change backgroundTint in xml it works. So is there way to change icon color?

0 Answers
Related