Answer the question
In order to leave comments, you need to log in
Why does the color of the layout not change only after “sleep”?
I would like to make the layout be green for a second, and then turn white. But it turns out that the color does not change at the beginning, but the dream works. How to make it work??
((RelativeLayout)findViewById(R.id.rel_layout)).setBackgroundColor(getResources().getColor(android.R.color.holo_green_dark));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
((RelativeLayout)findViewById(R.id.rel_layout)).setBackgroundColor(getResources().getColor(android.R.color.white));
Answer the question
In order to leave comments, you need to log in
Call sleep on another thread. For example, through AsyncTask.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question