我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让大家最 容易想到的就是progressbar或者progressDialog,区别在于前者是一个控件,后者是对话框。由于一些需求在弹出进度条时不希望用户 能够操作其他控件,所以只能使用progressDialog,这个时候有遇到了一个问题,我不想要progressDialog的黑色框框,感觉这样跟 应用的整体风格不协调,这个时候就考虑了写一个自定义的progressDialog。

在网上搜过很多自定义progressDialog的例子,对着写了下,但是没有任何效果,不知道是自己使用的方法不对还是什么地方出错了。通过不断的查找资料,写了一个简单的自定义progressDialog。先上图看下效果:

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

@null

true

@null

@android:style/Animation.Dialog

stateUnspecified|adjustPan

@android:color/transparent

true

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

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal">

android:id="@+id/loadingImageView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@anim/progress_round"/>

android:id="@+id/id_tv_loadingmsg"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:textSize="20dp"/>

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

xmlns:android="http://schemas.android.com/apk/res/android"

android:oneshot="false">

4.CustomProgressDialog.java文件,这个是就是我们最终需要使用的progressDialog了。

/**************************************************************************************

* [Project]

* MyProgressDialog

* [Package]

* com.lxd.widgets

* [FileName]

* CustomProgressDialog.java

* [Copyright]

* Copyright 2012 LXD All Rights Reserved.

* [History]

* Version Date Author Record

*--------------------------------------------------------------------------------------

* 1.0.0 2012-4-27 lxd (rohsuton@gmail.com) Create

**************************************************************************************/

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;

}

}

android 自定义progressdialog,Android 自定义progressDialog实现相关推荐

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

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

  2. android 获取对话框对象,Android 基本Dialog和自定义Dialog

    Android 基本Dialog和自定义Dialog Dialog类是对话框的基类,但你应该避免直接实例化Dialog ,可以使用子类 1.AlertDialog 此对话框可以显示标题,最多三个按钮, ...

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

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

  4. android 自定义带输入框的dialog,Android 基本Dialog和自定义Dialog

    Android 基本Dialog和自定义Dialog Dialog类是对话框的基类,但你应该避免直接实例化Dialog ,可以使用子类 1.AlertDialog 此对话框可以显示标题,最多三个按钮, ...

  5. android炫酷的自定义view,Android自定义View实现炫酷进度条

    本文实例为大家分享了Android实现炫酷进度条的具体代码,供大家参考,具体内容如下 下面我们来实现如下效果: 第一步:创建attrs文件夹,自定义属性: 第二步:自定义View: /** * Cre ...

  6. android单线字体,Android自定义字体

    在main文件夹下,新建assets/fonts文件,添加.otf文件 image.png 字体工具类 import android.app.Application; import android.g ...

  7. android 自定义命名空间,Android自定义ActionBar实例

    本文实例讲述了android自定义actionbar的实现方法.分享给大家供大家参考.具体实现方法如下: android 3.0及以上已经有了actionbar的api,可以通过引入support p ...

  8. android 自定义图片容器,Android应用开发中自定义ViewGroup视图容器的教程

    一.概述在写代码之前,我必须得问几个问题: 1.ViewGroup的职责是啥?ViewGroup相当于一个放置View的容器,并且我们在写布局xml的时候,会告诉容器(凡是以layout为开头的属性, ...

  9. android sqlite自定义函数,Android中自定义一个View的方法详解

    本文实例讲述了Android中自定义一个View的方法.分享给大家供大家参考,具体如下: Android中自定义View的实现比较简单,无非就是继承父类,然后重载方法,即便如此,在实际编码中难免会遇到 ...

最新文章

  1. 笔试算法题(58):二分查找树性能分析(Binary Search Tree Performance Analysis)
  2. 后退N帧协议-GBN
  3. 最先进的计算机视觉|AI和工业4.0之间,还有多远的差距?
  4. mysql中数据表如何关联_mysql 如何导入/导出2个关联表中的数据
  5. java中ofd文件转pdf_word文件转pdf怎么转?这一招轻松搞定Word转PDF
  6. 详解KMP算法原理,以及完整java与C++实现
  7. php html xml,xml和html之间的区别有哪些
  8. 如何使用ABBYY FineReader 12将JPEG文件转换成Word文档
  9. python列表是顺序表还是链表_顺序表与链表
  10. java高级规范_Java高级规范之二
  11. Pycharm 的设置--参数设置(运行.py文件带参数,例如argument)
  12. ARP表和MAC表的区别
  13. 超1200张!《Nature》高清论文插图集下载
  14. 直线插补算法---matlab仿真程序
  15. MindManager2021补丁注册码激活码生成器
  16. 人体动作捕捉与SMPL模型 (mocap and SMPL model)
  17. KILE生成S19或者BIN文件
  18. 大聪明教你学Java | EasyExcel - 用更简单的方式操作Excel
  19. Gentoo 2005.1 完整的USE参数清单中文详解
  20. MicroLab专业的嵌入式开发调试工具集免费试用

热门文章

  1. 初窥Java哈希(如何解决Hash冲突)
  2. mes系统与Oracle对接,Oracle ERP系统与MES系统的接口分析与实现
  3. NullPointException
  4. C#ref和out参数
  5. 产业分析:2022保险行业展望
  6. 服务与服务产品的趋势与未来
  7. 程序之三高(高可用、高性能、高并发)
  8. 问题记录:mac系统偏好设置不展示mysql
  9. 爱情淡了也不要说分手
  10. 抖音直播间商品怎么上架?低粉新号快速引流玩法来了!