Animate change of view background color on Android

前端 未结 16 1006
孤街浪徒
孤街浪徒 2020-11-22 13:23

How do you animate the change of background color of a view on Android?

For example:

I have a view with a red background color. The background color of the

16条回答
  •  庸人自扰
    2020-11-22 14:03

    add a folder animator into res folder. (the name must be animator). Add an animator resource file. For example res/animator/fade.xml

    
    
        
    
    

    Inside Activity java file, call this

    View v = getWindow().getDecorView().findViewById(android.R.id.content);
    AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.fade);
    set.setTarget(v);
    set.start();
    

提交回复
热议问题