简单的进度条,圆形进度条(一)

1.  ProgressActivityDemo.java

public class ProgressActivityDemo extends AppCompatActivity {
    private Button progressButton = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_activity_demo);
        this.progressButton = (Button)findViewById(R.id.internet_button);
        this.progressButton.setOnClickListener(new OnClickListenerImpl());
    }

    private class OnClickListenerImpl implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            final ProgressDialog progressDialog = ProgressDialog.show(ProgressActivityDemo.this,
                    "search internet",    //对话框显示标题
                    "please waitting...");    //对话框显示文字
            new Thread() {  //线程对象
                @Override
                public void run() {
                    try {
                        Thread.sleep(3000);     // 运行3秒关闭对话框
                    } catch (InterruptedException e) {
                    } finally {
                        progressDialog.dismiss();
                    }
                }
            }.start();
            progressDialog.show();   //显示对话框
        }
    }
}

2.activity_progress_activity_demo.xml

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="find internet connection"
    android:id="@+id/internet_button"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="76dp" />

3.  上面采用的是构造方法来实现,也可以是采用如下的方法实现。

public class ProgressActivityDemo extends AppCompatActivity {
    private Button progressButton = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_activity_demo);
        this.progressButton = (Button)findViewById(R.id.internet_button);
        this.progressButton.setOnClickListener(new OnClickListenerImpl());
    }

    private class OnClickListenerImpl implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            final ProgressDialog progressDialog = new ProgressDialog(ProgressActivityDemo.this);
            progressDialog.setTitle("search internet");//对话框显示标题
            progressDialog.setMessage( "please waitting...");   //对话框显示文字
            progressDialog.onStart();
            new Thread() {  //线程对象
                @Override
                public void run() {
                    try {
                        Thread.sleep(3000);     // 运行3秒关闭对话框
                    } catch (InterruptedException e) {
                    } finally {
                        progressDialog.dismiss();
                    }
                }
            }.start();
            progressDialog.show();   //显示对话框
        }
    }
}


你可能感兴趣的:(简单的进度条,圆形进度条(一))