一个常用的自定义弹框封装(适配 AndroidX),加载 ProgressDialog,状态显示的 StatusDialog 和自定义 Toast,全部支持背景颜色,圆角,边框和文字的自定义,构建者模
MNProgressHUD
项目地址:maning0303/MNProgressHUD
简介: 一个常用的自定义弹框封装(适配 AndroidX),加载 ProgressDialog,状态显示的 StatusDialog 和自定义 Toast,全部支持背景颜色,圆角,边框和文字的自定义,构建者模式,链式调用。
更多:作者 提 Bug
标签:
一个常用的自定义弹框封装(适配 AndroidX),加载 ProgressDialog,状态显示的 StatusDialog 和自定义 Toast,全部支持背景颜色,圆角,边框和文字的自定义,构建者模式,链式调用。
截图:
MProgressDialog
转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消
MProgressBarDialog (水平进度条和圆形进度条)
转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消
MStatusDialog
转存失败重新上传取消 转存失败重新上传取消
MSToast
转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消 转存失败重新上传取消
如何添加
1:Gradle 添加:
1.在 Project 的 build.gradle 中添加仓库地址
allprojects {repositories {...maven { url "" }}}
Android X 适配版本源码
Android Support 适配版本源码
2.在 app 目录下的 build.gradle 中添加依赖
//android support librarydependencies {implementation 'com.android.support:appcompat-v7:28.0.0'implementation 'com.android.support:support-v4:28.0.0'implementation 'com.github.maning0303:MNProgressHUD:V2.0.0'}//android x 适配dependencies {implementation 'androidx.appcompat:appcompat:1.1.0'implementation 'androidx.legacy:legacy-support-v4:1.0.0'implementation 'com.github.maning0303:MNProgressHUD:V2.0.0X'}
2:源码 Module 添加:
直接关联 mndialoglibrary(需要 android x 适配,切换到 androidx 分支。)
implementation project(':mndialoglibrary')
使用方法(查看 Demo 详情):
1:MProgressDialog 加载 Dialog 代码使用:
//默认MProgressDialog.showProgress(this);//自定义文字MProgressDialog.showProgress(this,"自定义文字");//不需要文字MProgressDialog.showProgress(this,"");//自定义背景MDialogConfig mDialogConfig = new MDialogConfig.Builder()//设置 dialog 最小宽度和最小高度.setMinWidthAndHeight(50,50)//全屏模式.isWindowFullscreen(true)//Progress 大小(宽高).setProgressSize(60)//点击外部是否可以取消.isCanceledOnTouchOutside(true)//物理返回键可以取消.isCancelable(true)//全屏背景窗体的颜色.setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))//View 背景的颜色.setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg))//View 背景的圆角.setCornerRadius(20)//View 边框的颜色.setStrokeColor(getMyColor(R.color.colorAccent))//View 边框的宽度.setStrokeWidth(2)//Progress 颜色.setProgressColor(getMyColor(R.color.colorDialogProgressBarColor))//Progress 宽度.setProgressWidth(3)//Progress 内圈颜色.setProgressRimColor(Color.YELLOW)//Progress 内圈宽度.setProgressRimWidth(4)//文字的颜色.setTextColor(getMyColor(R.color.colorDialogTextColor))//ProgressBar 颜色.setProgressColor(Color.GREEN)//dialog 动画.setAnimationID(R.style.animate_dialog_custom)//文字的大小:sp.setTextSize(15)//padding.setPadding(40, 10, 40, 10)//关闭的监听.setOnDialogDismissListener(new OnDialogDismissListener() {@Overridepublic void onDismiss() {MToast.makeTextShort(mContext,"监听到了 ProgressDialog 关闭了");}}).build();MProgressDialog.showProgress(this,"数据上传中...",mDialogConfig);
2:MStatusDialog 状态 Dialog 代码使用:
//默认MStatusDialog mStatusDialog = new MStatusDialog(this);//显示mStatusDialog.show("保存成功", mContext.getResources().getDrawable(R.drawable.mn_icon_dialog_ok));//手动取消mStatusDialog.dismiss();//自定义MDialogConfig mDialogConfig = new MDialogConfig.Builder()//全屏模式.isWindowFullscreen(true)//全屏背景窗体的颜色.setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))//View 背景的颜色.setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg2))//字体的颜色.setTextColor(getMyColor(R.color.colorAccent))//View 边框的颜色.setStrokeColor(getMyColor(R.color.white))//View 边框的宽度.setStrokeWidth(2)//View 圆角大小.setCornerRadius(10)//dialog 动画.setAnimationID(R.style.animate_dialog_custom)//文字的大小 sp.setTextSize(15)//paddingdp.setPadding(40, 10, 40, 10)//图片的宽高 dp.setImgWidthAndHeight(60, 60)//关闭的监听.setOnDialogDismissListener(new OnDialogDismissListener() {@Overridepublic void onDismiss() {MToast.makeTextShort(mContext,"监听到了 MStatusDialog 关闭了");}}).build();new MStatusDialog(mContext,mDialogConfig).show("提交数据失败,请重新尝试!", mContext.getResources().getDrawable(R.mipmap.ic_launcher), 1000);
3:MToast 代码使用:
MToastConfig config = new MToastConfig.Builder()//设置显示的位置.setGravity(MToastConfig.MToastGravity.CENTRE)//文字的颜色.setTextColor(getMyColor(R.color.colorAccent))//背景色.setBackgroundColor(getMyColor(R.color.colorDialogTest))//背景圆角.setBackgroundCornerRadius(10)//背景边框的颜色.setBackgroundStrokeColor(Color.WHITE)//背景边框的宽度.setBackgroundStrokeWidth(1)//文字的大小:sp.setTextSize(15)//padding.setPadding(40, 10, 40, 10)//图片的宽高 dp.setImgWidthAndHeight(60, 60).build();//多种方法MToast.makeTextShort(mContext, "Toast", config);MToast.makeTextShort(mContext, "Toast");//取消 ToastMToast.cancleToast();
4:MProgressBarDialog 进度条 Dialog 代码使用:
//新建一个 DialogmProgressBarDialog = new MProgressBarDialog.Builder(mContext)//全屏模式.isWindowFullscreen(true).setStyle(MProgressBarDialog.MProgressBarDialogStyle_Circle)//全屏背景窗体的颜色.setBackgroundWindowColor(getMyColor(R.color.colorDialogWindowBg))//View 背景的颜色.setBackgroundViewColor(getMyColor(R.color.colorDialogViewBg2))//字体的颜色.setTextColor(getMyColor(R.color.colorAccent))//View 边框的颜色.setStrokeColor(getMyColor(R.color.white))//View 边框的宽度.setStrokeWidth(2)//View 圆角大小.setCornerRadius(10)//ProgressBar 背景色.setProgressbarBackgroundColor(Color.BLUE)//ProgressBar 颜色.setProgressColor(Color.GREEN)//圆形内圈的宽度.setCircleProgressBarWidth(4)//圆形外圈的宽度.setCircleProgressBarBackgroundWidth(4)//水平进度条 Progress 圆角.setProgressCornerRadius(0)//水平进度条的高度.setHorizontalProgressBarHeight(10)//dialog 动画.setAnimationID(R.style.animate_dialog_custom).build();/*** 显示 dialog** @param progress 当前进度* @param secondProgress 二级进度* @param message 消息体* @param animate 是否平滑过度动画*/mMProgressDialog.showProgress(int progress,int secondProgress, String message, boolean animate);
版本记录:
V2.0.0:1.修复动画不居中问题2.监听 dialog 消失方法优化3.MProgressDialog 添加最小宽度和最小高度的设置4.MProgressDialog 默认不显示文字V1.1.9:1.当设置应用的 theme 背景为黑色后,加载框会覆盖覆盖全屏,是全屏变黑 问题优化2.MToast 支持异步线程3.去掉 FragmentDialog
感谢:
源码里面使用了下面库,改了个名字,以免冲突,非常感谢!
materialish-progress
CircularProgressBar
推荐:
Name | Describe | |
---|---|---|
GankMM | (Material Design & MVP & Retrofit + OKHttp & RecyclerView ...)Gank.io Android 客户端:每天一张美女图片,一个视频短片,若干 Android,iOS 等程序干货,周一到周五每天更新,数据全部由 干货集中营 提供,持续更新。 | |
MNUpdateAPK | Android APK 版本更新的下载和安装,适配 7.0,8.0,简单方便。 | |
MNImageBrowser | 交互特效的图片浏览框架,微信向下滑动动态关闭 | |
MNCalendar | 简单的日历控件练习,水平方向日历支持手势滑动切换,跳转月份;垂直方向日历选取区间范围。 | |
MClearEditText | 带有删除功能的 EditText | |
MNCrashMonitor | Debug 监听程序崩溃日志,展示崩溃日志列表,方便自己平时调试。 | |
MNProgressHUD | MNProgressHUD 是对常用的自定义弹框封装,加载 ProgressDialog,状态显示的 StatusDialog 和自定义 Toast,支持背景颜色,圆角,边框和文字的自定义。 | |
MNXUtilsDB | xUtils3 数据库模块单独抽取出来,方便使用。 | |
MNVideoPlayer | SurfaceView + MediaPlayer 实现的视频播放器,支持横竖屏切换,手势快进快退、调节音量,亮度等。------代码简单,新手可以看一看。 | |
MNZXingCode | 快速集成二维码扫描和生成二维码 | |
MNChangeSkin | Android 夜间模式,通过 Theme 实现 | |
SwitcherView | 垂直滚动的广告栏文字展示。 | |
MNPasswordEditText | 类似微信支付宝的密码输入框。 | |
MNSwipeToLoadDemo | 利用 SwipeToLoadLayout 实现的各种下拉刷新效果(饿了吗,京东,百度外卖,美团外卖,天猫下拉刷新等)。 |
发布者:admin,转转请注明出处:http://www.yc00.com/news/1701553869a1114884.html
评论列表(0条)