public void onClick(View v) {
if (v == b1) {
b1.setBackgroundColor(Color.WHITE);
delay(300);
b1.setBackgroundColor(Color.GREEN);
}
//-------------------------------------------------------------- /** * @param ms time of delay */
public void delay(int ms) {
checkDelayArgument(ms);
Thread thread = Thread.currentThread();
if (!thread.isInterrupted()) {
try {
Thread.sleep(ms);
} catch (final InterruptedException ignored) {
thread.interrupt(); // Preserve interrupt status
}
}
}
/**
* @param ms time of delay
*/
private static void checkDelayArgument(int ms) {
if (ms < 0 || ms > 60000) {
throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
}
}
//--------------------------------------------------------------
Result: Only green color change and i don't see the change of white color