写点什么

android 各种提示 Dialog 弹出框 (1)

用户头像
Android架构
关注
发布于: 2021 年 11 月 07 日

public static Dialog getProcessDialog(Activity activity, CharSequence message,


boolean dismissTouchOutside, boolean cancelable) {


final LayoutInflater inflater = LayoutInflater.from(activity);


View v = inflater.inflate(R.layout.progress_hud, null);


Dialog dialog = getCustomDialog(activity, v, dismissTouchOutside, cancelable, -1);


if (dismissTouchOutside) {


dialog.setCanceledOnTouchOutside(true);


} else {


dialog.setCanceledOnTouchOutside(false);


}


ImageView spinner = (ImageView) v.findViewById(R.id.spinnerImageView);


((AnimationDrawable) spinner.getBackground()).start();


TextView messageTv = (TextView) v.findViewById(R.id.message);


if (TextUtils.isEmpty(message)) {


messageTv.setVisibility(View.GONE);


} else {


messageTv.setText(message);


messageTv.setVisibility(View.VISIBLE);


}


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


return dialog;


}


public static Dialog getCustomDialog(final Activity activity, View view, boolean dismissTouchOutside,


boolean cancelable, int theme) {


//Dialog dialog = theme > 0 ? new FullScreenDialogHUD(activity, theme)


// : new Dialog(activity, R.style.Dialog_FullScreen);


Dialog dialog = new Dialog(activity, R.style.Dialog_FullScreen);


dialog.setContentView(view);


dialog.setCancelable(cancelable);


dialog.setCanceledOnTouchOutside(dismissTouchOutside);


if (!cancelable) {


dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {


@Override


public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {


if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {


dialog.dismiss();


activity.finish();


}


return false;


}


});


}


return dialog;


}


public static Dialog getOneButtonDialog(final Activity activity, String content,


boolean dismissTouchOutside, boolean cancelable,


DialogInterface.OnClickListener confirmOnClickListener) {


Dialog dialog = new AlertDialog.Builder(activity)


.setPositiveButton(R.string.confirm, confirmOnClickListener)


.setCancelable(cancelable)


.setMessage(content)


.create();


dialog.setCanceledOnTouchOutside(dismissTouchOutside);


if (!cancelable) {


dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {


@Override


public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {


if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {


dialog.dismiss();


activity.finish();


}


return false;


}


});


}


return dialog;


}


public static Dialog getButtonsDialog(Activity activity, int resId,


DialogInterface.OnClickListener confirmOnClickListener) {


return getButtonsDialog(activity, activity.getString(resId), true, true, confirmOnClickListener,


null);


}


public static Dialog getButtonsDialog(Activity activity, String content,


DialogInterface.OnClickListener confirmOnClickListener) {


return getButtonsDialog(activity, content, true, true, confirmOnClickListener, null);


}


public static Dialog getButtonsDialog(Activity activity, String content, boolean dismissTouchOutside,


boolean cancelable, DialogInterface.OnClickListener confirmOnClickListener,


DialogInterface.OnClickListener cancelOnClickListener) {


Dialog dialog = new AlertDialog.Builder(activity)


.setNegativeButton(R.string.cancel, cancelOnClickListener)


.setPositiveButton(R.string.confirm, confirmOnClickListener)


.setCancelable(cancelable)


.setMessage(content)


.create();


dialog.setCanceledOnTouchOutside(dismissTouchOutside);


return dialog;


}


progress_hud.xml


<?xml version="1.0" encoding="utf-8"?>

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
android各种提示Dialog  弹出框(1)