A
A
artshelom2018-06-24 23:24:11
Android
artshelom, 2018-06-24 23:24:11

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

1 answer(s)
M
Mikhail Chvarkov, 2018-06-25
@artshelom

Call sleep on another thread. For example, through AsyncTask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question