Animate change of view background color on Android | android background color
Dependingonhowyourviewgetsitsbackgroundcolorandhowyougetyourtargetcolorthereareseveraldifferentwaystodothis.ThefirsttwousestheAndroidPropertyAnimation[1]framework.UseaObjectAnimator[2]if:Yourviewhaveitsbackgroundcolordefinedasaargbvalueinaxmlfile.Yourviewhavepreviouslyhaditscolorsetbyview.setBackgroundColor()YourviewhaveitsbackgroundcolordefinedinadrawablethatDOESNOTdefinesanyextrapropertieslikestrokeorcornerradiuses.Yourviewhaveitsbackgroundcolordefinedinadrawableandyouwanttoremoveanyextrap...
Depending on how your view gets its background color and how you get your target color there are several different ways to do this.
The first two uses the Android Property Animation[1] framework.
Use a Object Animator[2] if:
Your view have its background color defined as a argb value in a xml file. Your view have previously had its color set by view.setBackgroundColor() Your view have its background color defined in a drawable that DOES NOT defines any extra properties like stroke or corner radiuses. Your view have its background color defined in a drawable and you want to remove any extra properties like stroke or corner radiuses, keep in mind that the removal of the extra properties will not animated.The object animator works by calling view.setBackgroundColor which replaces the defined drawable unless is it an instance of a ColorDrawable, which it rarely is. This means that any extra background properties from a drawable like stroke or corners will be re...