In Android, how do I smoothly fade the background from one color to another? (How to use threads)

后端 未结 6 2015
我寻月下人不归
我寻月下人不归 2020-12-23 09:59

I\'ve been playing with Android programming on and off for a couple of weeks, and I\'m trying to get something to work that seems simple, but I think I am missing something.

6条回答
  •  北海茫月
    2020-12-23 10:28

    I found another way to change the background color if you're interested--I think using animation will be easier than what you currently have :)

    If you are using API Level 11 or above, you can use ObjectAnimator on the background color of your LinearLayout.

     ObjectAnimator colorFade = ObjectAnimator.ofObject(screen, "backgroundColor", new ArgbEvaluator(), Color.argb(255,255,255,255), 0xff000000);
      colorFade.setDuration(7000);
      colorFade.start();
    

    Also, just a quick note, the 32-bit int color codes must be used. See http://developer.android.com/reference/android/graphics/Color.html for details but you can use Color.argb, Color.rgb, the hex as I used above, or look at the int color constants.

    Hope this helps!

提交回复
热议问题