下面列出了android.app.ProgressDialog#setContentView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void showProgressDialog(final View view, String title, String message){
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
ProgressDialogLayout progressDialogLayout = (ProgressDialogLayout) getActivity().getLayoutInflater().inflate(R.layout.progress_dialog_layout, null);
progressDialog.setCancelable(false);
progressDialogLayout.setTitle(title);
progressDialogLayout.setMessage(message);
progressDialogLayout.setButton(getString(R.string.word_cancel), new View.OnClickListener() {
@Override
public void onClick(View v) {
serviceConnection.scheduleTask(new Runnable() {
@Override
public void run() {
serviceConnection.getConnectionService().endService();
}
});
progressDialog.dismiss();
generateInvalidSnackBar(view, getString(R.string.connection_cancelled)).show();
loginProgressDialog = null;
}
});
progressDialog.show();
progressDialog.setContentView(progressDialogLayout);
loginProgressDialog = progressDialog;
}
public static ProgressDialog createProgressDialog(Context context,
String text) {
final ProgressDialog dlg = new ProgressDialog(context, R.style.Theme_Dialog_Default);
dlg.show();
dlg.setContentView(R.layout.loading_layout);
LinearLayout root = (LinearLayout) dlg
.findViewById(R.id.progressDialog);
root.setGravity(android.view.Gravity.CENTER);
root.getBackground().setAlpha(100);// 0~255透明度值 ,0为完全透明,255为不透明
LoadingView mLoadView = new LoadingView(context);
mLoadView.setDrawableResId(R.drawable.loading_img);
root.addView(mLoadView);
TextView alert = new TextView(context);
alert.setGravity(android.view.Gravity.CENTER);
alert.setHeight(50);
alert.setText(text);
alert.setTextColor(0xFFFFFFFF);
root.addView(alert);
dlg.setCanceledOnTouchOutside(false);
return dlg;
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProgressDialog dialog;
dialog = ProgressDialog.show(MainActivity.this,null,null);
dialog.setContentView(R.layout.progressbar);
dialog.show();
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
public static ProgressDialog showLoadingDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.show();
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}
private ProgressDialog createProgressDialog(Context mContext) {
ProgressDialog dialog = new ProgressDialog(mContext);
try {
dialog.show();
} catch (WindowManager.BadTokenException e) {}
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.progress_dialog);
return dialog;
}
public LoadingDialog(Context context, String text) {
this.context = context;
this.handler = new MyHandler();
dlg = new ProgressDialog(context, R.style.Theme_Dialog_Default);
dlg.show();
dlg.setContentView(R.layout.loading_layout);
LinearLayout root = (LinearLayout) dlg
.findViewById(R.id.progressDialog);
root.setGravity(android.view.Gravity.CENTER);
root.getBackground().setAlpha(100);// 0~255透明度值 ,0为完全透明,255为不透明
mLoadView = new LoadingView(context);
mLoadView.setDrawableResId(R.drawable.loading_img);
root.addView(mLoadView);
imgView = new ImageView(context);
imgView.setImageResource(R.drawable.loading_img);
root.addView(imgView);
imgView.setVisibility(View.GONE);
alert = new TextView(context);
alert.setGravity(android.view.Gravity.CENTER);
alert.setHeight(50);
alert.setText(text);
alert.setTextColor(0xFFFFFFFF);
root.addView(alert);
dlg.setCanceledOnTouchOutside(false);
}
public LoadingDialog(Context context, int resLayoutId, int resImgId,
String text, boolean isCanceledOnTouchOutside) {
this.context = context;
this.handler = new MyHandler();
dlg = new ProgressDialog(context, R.style.Theme_Dialog_Default);
dlg.show();
dlg.setContentView(resLayoutId);
LinearLayout root = (LinearLayout) dlg
.findViewById(R.id.progressDialog);
root.setGravity(android.view.Gravity.CENTER);
root.getBackground().setAlpha(100);// 0~255透明度值 ,0为完全透明,255为不透明
mLoadView = new LoadingView(context);
mLoadView.setDrawableResId(resImgId);
root.addView(mLoadView);
imgView = new ImageView(context);
imgView.setImageResource(R.drawable.loading_img);
root.addView(imgView);
imgView.setVisibility(View.GONE);
alert = new TextView(context);
alert.setGravity(android.view.Gravity.CENTER);
alert.setHeight(50);
alert.setText(text);
alert.setTextColor(0xFFFFFFFF);
root.addView(alert);
dlg.setCanceledOnTouchOutside(isCanceledOnTouchOutside);
}
private static ProgressDialog createAndShowWaitSpinner(Context mContext)
{
ProgressDialog dialog = new ProgressDialog(mContext);
try {
dialog.show();
}
catch (WindowManager.BadTokenException e) {
}
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.wait_spinner);
return dialog;
}