ProgressDialog

做一个这样的加载画面。一段时间后消失。

final Dialog dialog = ProgressDialog.show(this,"正在加载","数据加载中....");

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                dialog.dismiss();
                runOnUiThread(new Runnable(){
                    @Override
                    public void run(){
                        Toast.makeText(MainActivity.this,"加载完成",Toast.LENGTH_SHORT).show();
                    }

                });

            }

        }).start();
View Code

要注意的是,需要把等待和dismiss放到子线程中去。

还可以做一个水平的进度条

final ProgressDialog pd = new ProgressDialog(this);

        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

        pd.setTitle("正在处理");
        pd.show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                int end =100;
                pd.setMax(end);
                for(int i=0;i<end;i++){
                    pd.setProgress(i);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                pd.dismiss();

            }
        }).start();
View Code
原文地址:https://www.cnblogs.com/superxuezhazha/p/12732377.html