How to use animatorSet to change background color of a View

EdgeDev

I am aiming at animating different things simultaneously. I have successfully used AnimatorSet to scale up my textView

val textViewAnimatorX = ObjectAnimator.ofFloat(txtView, View.SCALE_X, 0.8f, 1.2f)
val textViewAnimatorY = ObjectAnimator.ofFloat(txtView, View.SCALE_Y, 0.8f, 1.2f)

val animatorSet = AnimatorSet()
animatorSet.playTogether(textViewAnimatorX, textViewAnimatorY)
animatorSet.setDuration(500)
animatorSet.start()

How can i use animator set to simultaneously change the root view background color?

Son Truong

Assume this is your layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">


    <TextView
        android:id="@+id/txtView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is text view" />

</LinearLayout>

Here is the code to simultaneously change the root view background color.

val textViewAnimatorX = ObjectAnimator.ofFloat(txtView, View.SCALE_X, 0.8f, 1.2f)
val textViewAnimatorY = ObjectAnimator.ofFloat(txtView, View.SCALE_Y, 0.8f, 1.2f)

// Create a new ObjectAnimator instance to change background color of root view.
val currentColor = rootView.solidColor
val newColor = Color.GREEN
val rootViewBackground = ObjectAnimator.ofObject(
    rootView,
    "backgroundColor",
    ArgbEvaluator(),
    currentColor,
    newColor
)

val animatorSet = AnimatorSet()
// Simultaneously change the root view background color.
animatorSet.playTogether(textViewAnimatorX, textViewAnimatorY, rootViewBackground)
animatorSet.setDuration(500)
animatorSet.start()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change AlertDialog view background color?

How to use mouseover effect to change the background color?

How to change background/color of the drawable set as background of a view?

Background color not change TextEditor view

Should you use an Image View for a solid background color, or change the background from the view?

How to change the background color

How to change the background color of a view from a different activity in android?

How to get and change drawable background color in custom view

How to change background view color partialy in ios swift

How to change UIWindow background color through a view controller

How to change Background Color of a View containing a List back to White in SwiftUI

iOS Swift - How to change background color of Table View?

How to change the background color of selected expandable table view cell

How to change the background color of tree-view in kivy python?

How to use a singleton timer in an attached behavior to change the background color on ListViewItems?

How to use a function to change background color with linear gradient?

How to use the setInterval method in javascript to change the body's background color?

How to set background color of a View

SwiftUI: how to make List view transparent? How to change List view background color?

Change background color of a view without removing drawable

Animate change of view background color on Android

Change Recycler view item background color by code

Unable to change background color of view in SwiftUI

change background color of view by its ID in Titanium

Change the background color of a Navigation View in Swift 5

How to change UIBezierPath background color?

How to change a background color for a row

How to change FAB background color

How to change background color of the snackbar?

TOP Ranking

HotTag

Archive