0

I have button called color. How can I change the Activity background color every 5 seconds?

Bryan Herbst
  • 65,094
  • 10
  • 126
  • 115
Zeljko
  • 1

3 Answers3

2

Quick google search: How to set background color of an Activity to white programmatically?

Put that in a loop with a Thread.sleep(5000) and wrap it with a function that sets the colors you want.

Community
  • 1
  • 1
gh123man
  • 1,282
  • 1
  • 13
  • 23
1

Do not sleep a thread , its a bad practice Create the object of your parent view in layout and use Async task to update the UI after a fixed interval in below method

 protected void onProgressUpdate(Integer... progress) {
         // interact with UI here
     }

see the docs for AsyncTask implementation.

Jitender Dev
  • 7,381
  • 2
  • 23
  • 37
0

You could use TimerTask

e.g.

Time timer = new Timer();
timer.scheduleAtFixedRate( new TimerTask(){
                public void run(){
                  //here set background
                }
                },0,5000);

For more details, http://developer.android.com/reference/java/util/Timer.html

MikeKeepsOnShine
  • 1,664
  • 4
  • 23
  • 35