ProgressDrialog 視窗
一般型
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("標題");
dialog.setMessage("等待中...");
dialog.show();
}
}
長條滾動型
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setIndeterminate(true);
dialog.show();
}
}
設定進度
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setIndeterminate(false);
dialog.incrementProgressBy(50);
dialog.incrementSecondaryProgressBy(75);
dialog.show();
}
}
設定視窗不可被使用者關閉
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressDialog dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.show();
}
}
設定按鈕
public class MainActivity extends Activity {
private Activity activity;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this;
ProgressDialog dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(activity, "關閉讀取視窗", Toast.LENGTH_SHORT).show();
}
});
dialog.show();
}
}