Android 自定义ProgressDialog进度条对话框用法详解

2019-12-10 19:13:58于丽

pd1.setIcon(R.drawable.secondback);// 设置ProgressDialog标题图标 
// 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确 
pd1.setIndeterminate(false); 
pd1.setCancelable(true); // 设置ProgressDialog 是否可以按退回键取消 
pd1.setProgress(100);// 设置ProgressDialog 进度条进度 
pd1.show(); // 让ProgressDialog显示 
count = 0; 
new Thread() { 
public void run() { 
try { 
while(count <= 100) { 
// 由线程来控制进度 
pd1.setProgress(count++); 
Thread.sleep(100); 

pd1.cancel(); 
} catch (Exception e) { 
pd1.cancel(); 


}.start(); 


}; 
//run的是实现 
public void run() { 
try { 
Thread.sleep(1000);//睡1秒 
} catch (InterruptedException e) { 
e.printStackTrace(); 

handler.sendEmptyMessage(0);//传送消息 

//定义处理消息的对象 
private Handler handler = new Handler(){ 
//加入传消息来了就这么么办 
public void handleMessage(Message msg){ 
pd.dismiss();//对话框消失 
Toast.makeText(SecondActivity.this, "对话框就消失了", 3).show(); 

}; 
// pdButton01的监听器类 
class Bt1DialogListener implements DialogInterface.OnClickListener { 
@Override 
public void onClick(DialogInterface dialog, int which) { 
// 点击“确定”按钮取消对话框 
dialog.cancel(); 



</span>



注:相关教程知识阅读请移步到Android开发频道。