Android objectAnimator animate backgroundColor of Layout

前端 未结 2 1984
感动是毒
感动是毒 2020-12-05 15:20

I have a problem. I want to animate the background color of a LinearLayout, using ObjectAnimator.
The problem is that it anima

2条回答
  •  抹茶落季
    2020-12-05 16:04

    I googled a bit. There is an answer. Try to use TransitionDrawable. http://developer.android.com/guide/topics/resources/drawable-resource.html#Transition

    Also, there is a topic somewhere on stackoverflow.com dedicated to the same problem.

    ADDED Code example:

        Button btn = (Button)this.findViewById(R.id.btn1);
        //Let's change background's color from blue to red.
        ColorDrawable[] color = {new ColorDrawable(Color.BLUE), new ColorDrawable(Color.RED)};
        TransitionDrawable trans = new TransitionDrawable(color);
        //This will work also on old devices. The latest API says you have to use setBackground instead.
        btn.setBackgroundDrawable(trans);
        trans.startTransition(5000);
    

提交回复
热议问题