先上图看下效果:

1.String.xml 文件,progressDialog是继承与Dialog,先设置一下progressDialog的风格,设置背景透明色。

<style name="CustomDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> </style> <style name="CustomProgressDialog" parent="@style/CustomDialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style>

2.customprogressdialog.xml文件,定义自己的布局,由于我的需求只需要一个进度条以及一串显示的内容,所以布局比较接单

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <ImageView android:id="@+id/loadingImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@anim/progress_round"/> <TextView android:id="@+id/id_tv_loadingmsg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textSize="20dp"/>
</LinearLayout>

3.progress_round.xml文件.这个文件为了实现转动的效果,循环显示这些图片。

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/progress_1" android:duration="200"/> <item android:drawable="@drawable/progress_2" android:duration="200"/> <item android:drawable="@drawable/progress_3" android:duration="200"/> <item android:drawable="@drawable/progress_4" android:duration="200"/> <item android:drawable="@drawable/progress_5" android:duration="200"/> <item android:drawable="@drawable/progress_6" android:duration="200"/> <item android:drawable="@drawable/progress_7" android:duration="200"/> <item android:drawable="@drawable/progress_8" android:duration="200"/>
</animation-list>

4.CustomProgressDialog.java文件

package com.lxd.widgets;import com.lxd.activity.R;import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;/********************************************************************* [Summary]*       TODO 请在此处简要描述此类所实现的功能。因为这项注释主要是为了在IDE环境中生成tip帮助,务必简明扼要* [Remarks]*       TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系.*******************************************************************/public class CustomProgressDialog extends Dialog {private Context context = null;private static CustomProgressDialog customProgressDialog = null;public CustomProgressDialog(Context context){super(context);this.context = context;}public CustomProgressDialog(Context context, int theme) {super(context, theme);}public static CustomProgressDialog createDialog(Context context){customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog);customProgressDialog.setContentView(R.layout.customprogressdialog);customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;return customProgressDialog;}public void onWindowFocusChanged(boolean hasFocus){if (customProgressDialog == null){return;}ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();animationDrawable.start();}/**** [Summary]*       setTitile 标题* @param strTitle* @return**/public CustomProgressDialog setTitile(String strTitle){return customProgressDialog;}/**** [Summary]*       setMessage 提示内容* @param strMessage* @return**/public CustomProgressDialog setMessage(String strMessage){TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg);if (tvMsg != null){tvMsg.setText(strMessage);}return customProgressDialog;}
}

5.调用

 CustomProgressDialog progressDialog = CustomProgressDialog.createDialog(this);

转载于:https://www.cnblogs.com/jxyZ/p/4082431.html

Android 自定义progressDialog实现相关推荐

  1. android 自定义progressdialog,Android 自定义progressDialog实现

    我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让大家最 容易想到的就是progressbar或者progres ...

  2. Android 自定义ProgressDialog

    Android本身已经提供了ProgressDialog进度等待框,使用该Dialog,我们可以为用户提供更好的体验:在网络请求时,弹出此框等待网络数据. 不过,既然是为了提高用户体验,我们肯定希望该 ...

  3. android自定义图片加载,Android自定义ProgressDialog加载图片

    为了提高用户体验,我们肯定希望该Dialog能更加炫酷,让用户看着更舒服.那如何做呢,当然是我们自己定义一个ProgressDialog了. 一.使用系统加载框 mDialog = new Progr ...

  4. android 自定义progressdialog,android自定义ProgressDialog加载效果

    用来记录自己所用到的知识 前两天在做项目的时候发现有时候在访问网络数据的时候由于后台要做的工作较多,给我们返回数据的时间较长,所以老大叫我加了一个加载中的logo图用来提高用户体验. 于是就在网上找了 ...

  5. android 自定义progressdialog,自定义ProgressDialog

    最近工作中需要用到progressDialog,可是系统自带的黑色progressDialog又是其丑无比,无奈只能自己自定义了,在网上查看别人的例子,并自己整理了一份Demo: 先上图: MyPro ...

  6. Android自定义类似ProgressDialog效果的Dialog

    2019独角兽企业重金招聘Python工程师标准>>> Android自定义类似ProgressDialog效果的Dialog. 方法如下: 1.首先准备两张自己要定义成哪样子的效果 ...

  7. android自定义对话框_Android自定义提醒对话框

    android自定义对话框 In this tutorial, we'll be discussing and implementing Custom Alert Dialogs in our And ...

  8. Android自定义ViewGroup基本步骤

    1.自定义属性,获取自定义属性,可参考 ​ Android自定义View基本步骤 ​ 2.onMeasure() 方法,for循环测量子View,根据子View的宽高来计算自己的宽 高 3.onDra ...

  9. Android自定义View —— TypedArray

    在上一篇中Android 自定义View Canvas -- Bitmap写到了TypedArray 这个属性 下面也简单的说一下TypedArray的使用 TypedArray 的作用: 用于从该结 ...

最新文章

  1. C语言 · 身份证号码升级
  2. 安卓给string对象赋值_String 面试题!看完让你恍然大悟!
  3. python知识:函数abs、delattr、hash、memeryview、index
  4. mysql 从裤3523_MySQL出现3523错误分析
  5. python语言input和if else的嵌套使用_Linux平台下Python if、if..else、if..elif..else、嵌套if语句...
  6. 小型移动 webApp Demo 知识点整理
  7. PMP读书笔记(第10章)
  8. rank,dense_rank,row_number使用和区别
  9. git在跟踪bug中的使用
  10. 换个名字卖到海外?海外版小米9T与Redmi K20 Pro配置相差无几
  11. vector的学习(系统的学习)
  12. 无人机图像深度学习的大豆害虫检测与分类
  13. 个人第三次软件工程作业-效能分析
  14. OSPF特殊区域的作用
  15. webstorm设置中文界面
  16. 如何使用命令行从图像中提取文本
  17. 文件管理大师android,文件管理大师
  18. Activity启动过程源码流程梳理和解读
  19. 怎样调整Firefox火狐浏览器开发者控制台字体大小
  20. java 7 反射_【7】java 反射详解

热门文章

  1. pip install报错_【Python】pip install django报错
  2. redis zset怎么排序_redis(set、zset)类型使用和使用场景
  3. python的软件环境是什么意思_python的虚拟环境详解
  4. golang debug 配置_新鲜出炉的golang日志库
  5. 如何使用cmd进入打印机选项_用命令添加打印机
  6. 局域网访问虚拟机服务器桥接,虚拟机让局域网访问的方法---桥接模式
  7. python中plt定义,对Python中plt的画图函数详解
  8. InnoDB如何实现多版本
  9. spark写入数据到elasticsearch
  10. Structured Streaming 入门案例之WordCount