做游戏ppt下载网站有哪些内容,中山模板建站公司,甘肃省城乡与住房建设厅网站,asp网站怎么运行#x1f4d6;封装加载弹框 ✅1. 构造LoadingDialog✅2. 调用LoadingDialog 效果#xff1a; ✅1. 构造LoadingDialog
构造LoadingDialog类涉及到设计模式中的建造者模式#xff0c;进行链式调用#xff0c;注重的是构建的过程#xff0c;设置需要的属性。
步骤一#x… 封装加载弹框 ✅1. 构造LoadingDialog✅2. 调用LoadingDialog 效果 ✅1. 构造LoadingDialog
构造LoadingDialog类涉及到设计模式中的建造者模式进行链式调用注重的是构建的过程设置需要的属性。
步骤一在utils包下创建LoadingDialog
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;public class LoadingDialog extends Dialog {public LoadingDialog(Context context, int themeResId) {super(context, themeResId);}public static class Builder {private Context context;//上下文private String message;//提示信息private boolean isShowMessage true;//是否显示提示信息private boolean isCancelable false;//返回键是否可以取消private boolean isCancelOutside false;//点击外部是否可以取消//构造方法传入上下文public Builder(Context context) {this.context context;}//设置提示信息public Builder setMessage(String message) {this.message message;return this;}//设置是否显示提示信息public Builder setShowMessage(boolean isShowMessage) {this.isShowMessage isShowMessage;return this;}//设置是否可以按返回键取消public Builder setCancelable(boolean isCancelable) {this.isCancelable isCancelable;return this;}//设置是否可以取消public Builder setCancelOutside(boolean isCancelOutside) {this.isCancelOutside isCancelOutside;return this;}//创建LoadingDialog对象public LoadingDialog create() {LayoutInflater inflater LayoutInflater.from(context);View view inflater.inflate(R.layout.dialog_loading, null);LoadingDialog loadingDailog new LoadingDialog(context, R.style.MyProgressDialog);TextView msgText (TextView) view.findViewById(R.id.messageTextView);if (isShowMessage) {msgText.setText(message);} else {msgText.setVisibility(View.GONE);}loadingDailog.setContentView(view);loadingDailog.setCancelable(isCancelable);loadingDailog.setCanceledOnTouchOutside(isCancelOutside);return loadingDailog;}}
}步骤二在layout文件下添加组件dialog_loading.xml
?xml version1.0 encodingutf-8?
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:gravitycenter!--白色color namewhite#ffffffff/color--LinearLayoutandroid:layout_width140dpandroid:layout_height100dpandroid:gravitycenterandroid:orientationverticalandroid:backgrounddrawable/shape_dialog_redius_grayProgressBarandroid:idid/progressBarandroid:layout_width40dpandroid:layout_height40dpandroid:layout_centerHorizontaltrueandroid:layout_centerVerticaltrueandroid:indeterminatetrueandroid:indeterminateTintandroid:color/white /TextViewandroid:idid/messageTextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_belowid/progressBarandroid:layout_centerHorizontaltrueandroid:layout_marginTop16dpandroid:textColorandroid:color/whiteandroid:textSize16sp //LinearLayout/RelativeLayout
步骤三在drawable文件下添加shapeshape_dialog_redius_gray.xml
?xml version1.0 encodingutf-8?
shape xmlns:androidhttp://schemas.android.com/apk/res/android !--黑色半透明color nameblack_transparent#98000000/color--solid android:colorcolor/black_transparent /corners android:radius5dp /
/shape步骤四在 values 文件下的themes.xml下添加如下主题 !--弹框加载样式--!--透明色color nametransparent#00000000/color--style nameMyProgressDialog parentTheme.AppCompat.Dialogitem nameandroid:windowBackgroundandroid:color/transparent/item!--背景透明--item nameandroid:windowIsFloatingtrue/item!--是否浮动--item nameandroid:backgroundDimEnabledfalse/item!--对话框背后的内容是否被暗淡--item nameandroid:windowContentOverlaynull/item!--设置窗口的内容覆盖物--item nameandroid:statusBarColornull/item!--状态栏背景色--/style✅2. 调用LoadingDialog
在点击事件或者发生http请求时显示弹框请求结束后关闭显示即可下面是使用1秒延时来模拟发送请求
private Handler mHandler new Handler();//全局定义send.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {//加载弹窗LoadingDialog loadingDialog new LoadingDialog.Builder(getActivity()).setMessage(加载中...).setCancelable(true)//返回键是否可关闭.setCancelOutside(false)//点击弹框外是否可关闭.create();//显示loadingDialog.show();//模拟异步发送请求后关闭加载弹窗mHandler.postDelayed(new Runnable() {Overridepublic void run() {//关闭显示loadingDialog.dismiss();}}, 1000);}});