工具Util

  1. public class DialogUtil {
  2.     public static ProgressDialogView progressDialog;
  3.     /**
  4.      * 显示对话框的方法,String类型
  5.      * @param context 句柄
  6.      * @param title 标题
  7.      * @param message 内容
  8.      * @param view 视图
  9.      * @param positive 左边的按钮文字
  10.      * @param neutral 中间的按钮文字
  11.      * @param negative 右边的按钮文字
  12.      * @param positiveListener 左边按钮的监听器
  13.      * @param neutralListener 中间按钮的监听器
  14.      * @param negativeListener 右边按钮的监听器
  15.      */
  16.     public static void showDialog(Context context, String title, String message, View view, String positive, String neutral,
  17.             String negative, OnClickListener positiveListener, OnClickListener neutralListener, OnClickListener negativeListener) {
  18.         new AlertDialog.Builder(context).setTitle(title).setMessage(message).setView(view)
  19.                 .setPositiveButton(positive, positiveListener).setNeutralButton(neutral, neutralListener)
  20.                 .setNegativeButton(negative, negativeListener).create().show();
  21.     }
  22.     /**
  23.      * 显示简单的带进度条对话框
  24.      * @param context 句柄
  25.      * @param title 标题
  26.      * @param message 内容
  27.      * @param cancelable 是否可以取消
  28.      */
  29.     public static void showProgressDialog(Context context, String title, String message, boolean cancelable, OnCancelListener cancelListener) {
  30.         dismissProgressDialog();
  31.         progressDialog = new ProgressDialogView(context);
  32.         progressDialog.setTitle(title);
  33.         progressDialog.setMessage(message);
  34.         progressDialog.setCancelable(cancelable);
  35.         progressDialog.setOnCancelListener(cancelListener);
  36.         progressDialog.show();
  37.     }
  38.     /**
  39.      * 取消带进度条的对话框
  40.      */
  41.     public static void dismissProgressDialog() {
  42.         if (progressDialog != null && progressDialog.isShowing()) {
  43.             try {
  44.                 progressDialog.dismiss();
  45.             } catch (IllegalArgumentException e) {
  46.             }
  47.         }
  48.         progressDialog = null;
  49.     }
  50. }
  51.  
  1.  

View

  1. public class ProgressDialogView extends Dialog {
  2.     private ProgressBar pgb_progress;
  3.     private TextView tv_messag;
  4.     public ProgressDialogView(Context context) {
  5.         super(context, R.style.DialogTheme);
  6.         initView();
  7.     }
  8.     public ProgressDialogView(Context context, int theme) {
  9.         super(context, theme);
  10.         initView();
  11.     }
  12.     private void initView() {
  13.         setContentView(R.layout.progress_dialog);
  14.         pgb_progress = (ProgressBar) findViewById(R.id.pgb_progress);
  15.         tv_messag = (TextView) findViewById(R.id.tv_messag);
  16.     }

  17.     @Override
  18.     public void setTitle(CharSequence title) {
  19.         super.setTitle(title);
  20.     }
  21.     @Override
  22.     public void setCancelable(boolean flag) {
  23.         super.setCancelable(flag);
  24.     }
  25.     @Override
  26.     public void setOnCancelListener(OnCancelListener listener) {
  27.         super.setOnCancelListener(listener);
  28.     }
  29.     public void setMessage(String string) {
  30.         tv_messag.setVisibility(View.VISIBLE);
  31.         tv_messag.setText(string);
  32.     }
  33. }

布局


  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="120dp"
  4.     android:layout_height="120dp"
  5.     android:background="@drawable/bg_progress_dialog"
  6.     android:orientation="vertical" >
  7.     <!-- android:background="@drawable/bg_progress_dialog" -->
  8.     <ProgressBar
  9.         android:id="@+id/pgb_progress"
  10.         android:layout_width="wrap_content"
  11.         android:layout_height="wrap_content"
  12.         android:layout_centerHorizontal="true"
  13.         android:layout_marginTop="18dp"
  14.         android:indeterminateDrawable="@drawable/progress_white" />
  15.     <TextView
  16.         android:id="@+id/tv_messag"
  17.         android:layout_width="wrap_content"
  18.         android:layout_height="wrap_content"
  19.         android:layout_below="@+id/pgb_progress"
  20.         android:layout_centerInParent="true"
  21.         android:layout_marginTop="5dp"
  22.         android:ellipsize="end"
  23.         android:singleLine="true"
  24.         android:text="显示信息"
  25.         android:textColor="@color/white"
  26.         android:textSize="18sp"
  27.         android:visibility="gone" />
  28. </RelativeLayout>

  29. 灰色背景 bg_progress_dialog
  30. <?xml version="1.0" encoding="utf-8"?>
  31. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  32.     <item><shape>
  33.             <solid android:color="#66000000" />
  34.             <corners android:radius="3dp" />
  35.             <padding android:bottom="6dp" android:left="3dp" android:right="3dp" android:top="6dp" />
  36.         </shape></item>
  37. </selector>

  38. 圆形进度条 progress_white

  39. <?xml version="1.0" encoding="UTF-8"?>
  40. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  41.     <item>
  42.         <rotate
  43.             android:drawable="@drawable/progress_white_icon"
  44.             android:fromDegrees="0.0"
  45.             android:pivotX="50.0%"
  46.             android:pivotY="50.0%"
  47.             android:toDegrees="360.0" />
  48.     </item>
  49. </layer-list>
  50.  
  1.  

95秀-dialog 进度对话框 实用工具的更多相关文章

  1. 95秀-自定义对话框 dialog 合集

    普通的确认对话框 NormalDialog.java import android.app.Dialog; import android.content.Context; import android ...

  2. Android—关于自定义对话框的工具类

    开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...

  3. Bootstrap<基础十> 响应式实用工具

    Bootstrap 提供了一些辅助类,以便更快地实现对移动设备友好的开发.这些可以通过媒体查询结合大型.小型和中型设备,实现内容对设备的显示和隐藏. 需要谨慎使用这些工具,避免在同一个站点创建完全不同 ...

  4. 10.Android之ProgressDialog进度对话框学习

    APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下. 首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条.代码如下: <?xml version=&quo ...

  5. Android Dialog(对话框)

    一个对话框一般是一个出现在当前Activity之上的一个小窗口. 处于下面的Activity失去焦点, 对话框接受所有的用户交互. 对话框一般用于提示信息和与当前应用程序直接相关的小功能. Andro ...

  6. Android学习笔记(九)——更复杂的进度对话框

    显示操作进度的对话框 1.使用上一篇创建的同一项目.在activity_main.xml文件里加入一个Button: <Button android:id="@+id/btn_dial ...

  7. 每位iOS开发人员不容错过的10大实用工具

    内容简介 1.iOS简介 2.iOS开发十大实用工具之开发环境 3.iOS开发十大实用工具之图标设计 4.iOS开发十大实用工具之原型设计 5.iOS开发十大实用工具之演示工具 6.iOS开发十大实用 ...

  8. Android学习笔记(八)——显示运行进度对话框

    显示运行进度对话框 我们经常有这种经历:运行某一应用程序时.须要等待一会,这时会显示一个进度(Please Wait)对话框,让用户知道操作正在进行. 我们继续在上一篇中的程序中加入代码~ 1.在上一 ...

  9. JavaScript和CSS实用工具、库与资源

    JavaScript和CSS实用工具.库与资源 JavaScript 库 Particles.js  - 一个用于在网页上创建漂亮的浮动粒子的 JS 库: Three.js  - 用于在网页上创建 3 ...

随机推荐

  1. Log4j实现对Java日志的配置全攻略

    1. 配置文件 Log4J配置文件的基本格式如下: #配置根Logger log4j.rootLogger = [ level ] , appenderName1 , appenderName2 , ...

  2. Redis学习 - 入门

    业精于勤,荒于嬉:行成于思,毁于随 -- 韩愈·<进学解>   因为工作中需要用到Redis,所以最近抽点时间看了一下,现在将学习的内容整理一下.   一.简介 1.Redis是什么? R ...

  3. C#.net 货币格式转换

    /// <summary> /// 输入Float格式数字,将其转换为货币表达方式 /// </summary> /// <param name="ftype& ...

  4. thinkphp框架之模型(数据库查询)

    1. 模型定义 文件名称必须是 表名+Model.class.php 例如:UserModel.class.php namespace Home\Model; //该模型类的命名空间 use Thin ...

  5. jquery cookies(2)用法实现

    example $.cookie('name', ‘value'); 设置cookie的值,把name变量的值设为value example $.cookie('name', ‘value', {ex ...

  6. Python hashlib模块 (主要记录md5加密)

    python提供了一个进行hash加密的模块:hashlib 下面主要记录下其中的md5加密方式(sha1加密一样把MD5换成sha1) >>> import hashlib > ...

  7. .net发邮件

    // 引入命名空间 using System.Net; using System.Net.Mail; SmtpClient smtp = new SmtpClient(); //实例化一个SmtpCl ...

  8. Swift互用性:与 C的API交互(Swift 2.0版)-b

    节包含内容: 基本数据类型(Primitive Types) 枚举(Enumerations) 指针(Pointer) 全局常量(Global Constants) 预处理指令(Preprocesso ...

  9. MATLAB文件操作及读txt文件

    转自:http://blog.csdn.net/vblittleboy/article/details/8049748 文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MA ...

  10. Keil uVISION2 自学教程

    Keil  uVISION2  是众多单片机应用开发软件中优秀的软件之一,它支持众多不同公司的 MCS-51 架构的芯片,它集编辑,编译,仿真等于一体,同时还支持.PLM.汇编和 C 语言的程序设计, ...