I would like to write simple application that changes continiously it's color from red to blue at specified intervals of time, so it simulates police siren. But I don't know how code so the application will be changing it's color.
here's what I've tried, of course it can't work...
LinearLayout mainBackground;
String currentColor = "Blue";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainBackground = (LinearLayout) findViewById(R.id.mainBackgroundID);
while(true) {
sleep(250);
if (currentColor.equals("Blue")) {
currentColor = "Red";
mainBackground.setBackgroundColor(0xFFFF0000);
} else {
currentColor = "Blue";
mainBackground.setBackgroundColor(0xFF0008FF);
}
}
}
Try this,