How to block UI for some seconds in android?

2019-04-12 04:04发布

How can i block UI from all interactions for some seconds by user in Android?

I would like to know, how to do this with some delay timing like wait(5000);

5条回答
淡お忘
2楼-- · 2019-04-12 04:37

Use ProgressDialog in UI Block time. Set ProgressDialog cancel-able false. So user do not able to access UI.

Thanks.

查看更多
家丑人穷心不美
3楼-- · 2019-04-12 04:43

Show Non-cancelable progress dialog and close it by code when you want.......

see example

http://www.helloandroid.com/tutorials/using-threads-and-progressdialog

查看更多
我想做一个坏孩纸
4楼-- · 2019-04-12 04:51

As your Question is Short, you will get answer in that manner.

You can use Thread or AsyncTask for making some ProgressDialog being Visible for the User.

查看更多
Animai°情兽
5楼-- · 2019-04-12 04:55

You can pop up a modal, non-cancelable progress dialog that blocks the user from doing anything. However, you should never block the UI thread itself.

查看更多
走好不送
6楼-- · 2019-04-12 05:00

You can override dispatchTouchEvent and stop the call to super.dispatchTouchEvent(ev); Any touch event will have to go through this method before it is handled.

Set a boolean that you control and use it in the method to determine whether you wish to block control.

private boolean stopUserInteractions = false;

public boolean dispatchTouchEvent(MotionEvent ev) {
    if (stopUserInteractions) {
        return true;
    } else {
        return super.dispatchTouchEvent(ev);
    }
}
查看更多
登录 后发表回答