For my app, I want a strobe light with multi colors to play, how do I do this?
-
You want the full source code of your app? – Waza_Be Aug 08 '12 at 19:36
-
1Welcome to Stack Overflow! [What have you tried?](http://whathaveyoutried.com) – Matt Ball Aug 08 '12 at 19:37
2 Answers
If you want different colors and such, then you can just create a View
in your XML to take up the whole screen width. Then based on an AlarmManager
you can use setBackground()
to make it a color of your choice.
It might be more beneficial to use a Handler
instead of AlarmManager
, but you can look at both to see what suits your needs.

- 10,440
- 8
- 52
- 79
If you want your screen to flash with different colors, that is just a matter of making a timer and having the main view change background colors every so often.
javax.swing.Timer can be used to change the screen every so often:
Timer colorChanger = new Timer(500 /*milis between each color change*/, new TimeListener(this) );
colorChanger.start();
Where TimeListener
will be an ActionListener
that changes the background color of a specified activity. TimerListener could look like this:
public class TimerListener implements ActionListener {
public TimerListener(Activity activity) {
this.backgroundToChange = activity;
}
private Activity backgroundToChange = null; // the activity who's background we will change
private int numFrames = 0; //the number of frames that have passed
public void actionPerformed(ActionEvent evt) { //happens when the timer will go off
numFrames++;
switch ( numFrames % 2 ) { // every other time it will make the background red or green
case 0: backgroundToChange.getContentView().setBackgroundColor(Color.RED);
case 1: backgroundToChange.getContentView().setBackgroundColor(Color.GREEN);
}
}
}
You're gonna need to import javax.swing.Timer and ActionListener and ActionEvent are in java.awt.event.
If you're using android however, you might want to consider using another class that is designed for android other than Timer. Timer is designed for swing and might not work well if you are using it on android. Any other timer like class will work similar to Timer though.

- 545
- 3
- 11