android 自定义提示框、对话框、加载框

项目实现项目地址: https://github.com/fingerth/FingerthAndroidUtils 点击使用方法

  • 使用方法
  • Step 1. Add the JitPack repository to your build file
  • Add it in your root build.gradle at the end of repositories:

allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

  • Step 2. Add the dependency

dependencies { compile 'com.github.fingerth:FingerthAndroidUtils:1.0.3' } 三、使用

  • 代码1

SYSDiaLogUtils.showSuccessDialog(this, false);

SYSDiaLogUtils.dismissProgress()    //停止

  • 效果图1 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码2

SYSDiaLogUtils.showSuccessDialog(this, "操作成功", "恭喜你,操作成功了!", "OK", false);

  • 效果图2 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码3

SYSDiaLogUtils.showInfoDialog(this, "操作提示", "很抱歉,你還不夠硬氣!", "取消", false);

  • 效果图3 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码4

SYSDiaLogUtils.showErrorDialog(this, "錯誤警告", "很抱歉,你這次真的是錯了,請重新試試!", "取消", false);

  • 效果图4 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码5

SYSDiaLogUtils.showSystemProgressDialog(this, "標題", "", false, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Toast.makeText(MainActivity.this, "點擊消失", Toast.LENGTH_SHORT).show(); } });

  • 效果图5 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码6

SYSDiaLogUtils.showProgressDialog(this, SYSDiaLogUtils.SYSDiaLogType.IosType, "加載中...", false, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Toast.makeText(MainActivity.this, "點擊消失", Toast.LENGTH_SHORT).show(); } });

  • 效果图6 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码7

SYSDiaLogUtils.showProgressBar(this, "", "", false, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (SYSDiaLogUtils.getProgressBar() < 100) { if (asyncTaskProgress != null) { asyncTaskProgress.cancel(true); } SYSDiaLogUtils.showErrorDialog(MainActivity.this, "下載失敗", "由於你取消了下載,導致下載失敗!", "確定", false); } } }); asyncTaskProgress = new AsyncTaskProgress(); asyncTaskProgress.execute("");

  • 效果图7 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码8

SYSDiaLogUtils.showProgressBar(this, SYSDiaLogUtils.SYSDiaLogType.HorizontalWithNumberProgressBar, "正在加載..."); asyncTaskProgress = new AsyncTaskProgress(); asyncTaskProgress.execute("");

  • 效果图8 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码9

SYSDiaLogUtils.showProgressBar(this, SYSDiaLogUtils.SYSDiaLogType.RoundWidthNumberProgressBar, "正在加載..."); asyncTaskProgress = new AsyncTaskProgress(); asyncTaskProgress.execute("");

  • 效果图9 
    【工具类】Android自定义提示框、对话框、加载框

  • 代码10

SYSDiaLogUtils.showConfirmDialog(this, true, SYSDiaLogUtils.SYSConfirmType.Tip, "標題", "我是提示!", new SYSDiaLogUtils.ConfirmDialogListener() { @Override public void onClickButton(boolean clickLeft, boolean clickRight) { if (clickLeft) { Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show(); } else if (clickRight) { Toast.makeText(MainActivity.this, "right", Toast.LENGTH_SHORT).show(); } } });

  • 效果图10 
    【工具类】Android自定义提示框、对话框、加载框

  • AsyncTaskProgress 的代码

private AsyncTaskProgress asyncTaskProgress; private class AsyncTaskProgress extends AsyncTask<String, Integer, Object> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Object doInBackground(String... params) { for (int i = 0; i < 100; i++) { SystemClock.sleep(50); publishProgress(i + 1); } return params; } @Override protected void onProgressUpdate(Integer... values) { //horizontal_bar.setProgress(values[0] % 100); SYSDiaLogUtils.setProgressBar(values[0] % 100); if (values[0] == 100) { SYSDiaLogUtils.dismissProgress(); SYSDiaLogUtils.showSuccessDialog(MainActivity.this, false); } super.onProgressUpdate(values); } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); } }} 四、小结一下

  • 对话框,我一般都用系统提供的了,自定义bug太多,没有Google提供的稳定。

 

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可根据加载情况显示提示信息的载入视图,如,加载失败后提示"加载失败"、"网络连接失败"等等。用一个控件就可以管理整个的加载过程。确实方便了。项目地址:https://github.com/antonkrasov/AndroidProgressLayout 效果图:如何使用将<com.github.androidprogresslayout.ProgressLayout> 作为整个布局的根:<com.github.androidprogresslayout.ProgressLayout         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:id="@ id/progress_layout"         android:layout_width="match_parent"         android:layout_height="match_parent"               >     ...你的页面 </com.github.androidprogresslayout.ProgressLayout>2. 得到ProgressLayoutProgressLayout progressLayout = (ProgressLayout) this.findViewById(R.id.progress_layout);3. 通过progressLayout.showContent()来打开loading,或者你也可以使用属性:app:progress="true"mHandler.postDelayed(new Runnable() {     @Override     public void run() { //progressLayout.showContent();//加载成功,关闭loading progressLayout.showErrorText("加载失败");//加载失败,并显示提示信息     } }, 2000);利用Handler模拟了一个2秒的载入过程。如果载入成功,调用progressLayout.showContent()关闭loading。如果载入失败,调用progressLayout.showErrorText("加载失败")显示失败信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值