- 浏览: 198664 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
xyyx_nk:
在demo中没有下载的示例,能详细说一下怎么监听下载过程吗?比 ...
DhNet 网络http工具(带缓存功能哦) -dhroid文档 -
zhaoguowei998:
dhroid ioc模块对 加密混淆问题 -
zhaoguowei998:
你太牛了,佩服佩服,以后要多想你请教了
dhroid ioc模块对 加密混淆问题 -
白色蜻蜓:
转载下您的文章,已注明出处。
IOS开发之百度地图API应用 -
wenjiefeng:
你好,在andrioidpn-client客户端源码里,Not ...
Android 推送之原理与初触Androidpn(Android Push Notification)
我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让大家最 容易想到的就是progressbar或者progressDialog,区别在于前者是一个控件,后者是对话框。由于一些需求在弹出进度条时不希望用户 能够操作其他控件,所以只能使用progressDialog,这个时候有遇到了一个问题,我不想要progressDialog的黑色框框,感觉这样跟 应用的整体风格不协调,这个时候就考虑了写一个自定义的progressDialog。
在网上搜过很多自定义progressDialog的例子,对着写了下,但是没有任何效果,不知道是自己使用的方法不对还是什么地方出错了。通过不断的查找资料,写了一个简单的自定义progressDialog。先上图看下效果:
1.String.xml 文件,progressDialog是继承与Dialog,先设置一下progressDialog的风格,设置背景透明色。
01 |
< style name = "CustomDialog" parent = "@android:style/Theme.Dialog" >
|
02 |
< item name = "android:windowFrame" >@null</ item >
|
03 |
< item name = "android:windowIsFloating" >true</ item >
|
04 |
< item name = "android:windowContentOverlay" >@null</ item >
|
05 |
< item name = "android:windowAnimationStyle" >@android:style/Animation.Dialog</ item >
|
06 |
< item name = "android:windowSoftInputMode" >stateUnspecified|adjustPan</ item >
|
07 |
</ style >
|
08 |
|
09 |
< style name = "CustomProgressDialog" parent = "@style/CustomDialog" >
|
10 |
< item name = "android:windowBackground" >@android:color/transparent</ item >
|
11 |
< item name = "android:windowNoTitle" >true</ item >
|
12 |
</ style >
|
2.customprogressdialog.xml文件,定义自己的布局,由于我的需求只需要一个进度条以及一串显示的内容,所以布局比较接单
01 |
<? xml version = "1.0" encoding = "utf-8" ?>
|
02 |
< LinearLayout |
03 |
xmlns:android = "http://schemas.android.com/apk/res/android" |
04 |
android:layout_width = "fill_parent" |
05 |
android:layout_height = "fill_parent" |
06 |
android:orientation = "horizontal" >
|
07 |
< ImageView |
08 |
android:id = "@+id/loadingImageView" |
09 |
android:layout_width = "wrap_content" |
10 |
android:layout_height = "wrap_content" |
11 |
android:background = "@anim/progress_round" />
|
12 |
< TextView |
13 |
android:id = "@+id/id_tv_loadingmsg" |
14 |
android:layout_width = "wrap_content" |
15 |
android:layout_height = "wrap_content" |
16 |
android:layout_gravity = "center_vertical" |
17 |
android:textSize = "20dp" />
|
18 |
</ LinearLayout >
|
3.progress_round.xml文件.这个文件为了实现转动的效果,循环显示这些图片。
01 |
<? xml version = "1.0" encoding = "utf-8" ?>
|
02 |
< animation-list |
03 |
xmlns:android = "http://schemas.android.com/apk/res/android" |
04 |
android:oneshot = "false" >
|
05 |
< item android:drawable = "@drawable/progress_1" android:duration = "200" />
|
06 |
< item android:drawable = "@drawable/progress_2" android:duration = "200" />
|
07 |
< item android:drawable = "@drawable/progress_3" android:duration = "200" />
|
08 |
< item android:drawable = "@drawable/progress_4" android:duration = "200" />
|
09 |
< item android:drawable = "@drawable/progress_5" android:duration = "200" />
|
10 |
< item android:drawable = "@drawable/progress_6" android:duration = "200" />
|
11 |
< item android:drawable = "@drawable/progress_7" android:duration = "200" />
|
12 |
< item android:drawable = "@drawable/progress_8" android:duration = "200" />
|
13 |
</ animation-list >
|
4.CustomProgressDialog.java文件,这个是就是我们最终需要使用的progressDialog了。
01 |
/************************************************************************************** |
02 |
* [Project] |
03 |
* MyProgressDialog |
04 |
* [Package] |
05 |
* com.lxd.widgets |
06 |
* [FileName] |
07 |
* CustomProgressDialog.java |
08 |
* [Copyright] |
09 |
* Copyright 2012 LXD All Rights Reserved. |
10 |
* [History] |
11 |
* Version Date Author Record |
12 |
*-------------------------------------------------------------------------------------- |
13 |
* 1.0.0 2012-4-27 lxd (rohsuton@gmail.com) Create |
14 |
**************************************************************************************/ |
15 |
|
16 |
package com.lxd.widgets;
|
17 |
18 |
19 |
import com.lxd.activity.R;
|
20 |
21 |
import android.app.Dialog;
|
22 |
import android.content.Context;
|
23 |
import android.graphics.drawable.AnimationDrawable;
|
24 |
import android.view.Gravity;
|
25 |
import android.widget.ImageView;
|
26 |
import android.widget.TextView;
|
27 |
28 |
29 |
/******************************************************************** |
30 |
* [Summary]
|
31 |
* TODO 请在此处简要描述此类所实现的功能。因为这项注释主要是为了在IDE环境中生成tip帮助,务必简明扼要
|
32 |
* [Remarks]
|
33 |
* TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系.
|
34 |
*******************************************************************/
|
35 |
36 |
public class CustomProgressDialog extends Dialog {
|
37 |
private Context context = null ;
|
38 |
private static CustomProgressDialog customProgressDialog = null ;
|
39 |
|
40 |
public CustomProgressDialog(Context context){
|
41 |
super (context);
|
42 |
this .context = context;
|
43 |
}
|
44 |
|
45 |
public CustomProgressDialog(Context context, int theme) {
|
46 |
super (context, theme);
|
47 |
}
|
48 |
|
49 |
public static CustomProgressDialog createDialog(Context context){
|
50 |
customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog);
|
51 |
customProgressDialog.setContentView(R.layout.customprogressdialog);
|
52 |
customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
|
53 |
|
54 |
return customProgressDialog;
|
55 |
}
|
56 |
|
57 |
public void onWindowFocusChanged( boolean hasFocus){
|
58 |
|
59 |
if (customProgressDialog == null ){
|
60 |
return ;
|
61 |
}
|
62 |
|
63 |
ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);
|
64 |
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
|
65 |
animationDrawable.start();
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
*
|
70 |
* [Summary]
|
71 |
* setTitile 标题
|
72 |
* @param strTitle
|
73 |
* @return
|
74 |
*
|
75 |
*/
|
76 |
public CustomProgressDialog setTitile(String strTitle){
|
77 |
return customProgressDialog;
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
*
|
82 |
* [Summary]
|
83 |
* setMessage 提示内容
|
84 |
* @param strMessage
|
85 |
* @return
|
86 |
*
|
87 |
*/
|
88 |
public CustomProgressDialog setMessage(String strMessage){
|
89 |
TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg);
|
90 |
|
91 |
if (tvMsg != null ){
|
92 |
tvMsg.setText(strMessage);
|
93 |
}
|
94 |
|
95 |
return customProgressDialog;
|
96 |
}
|
97 |
} |
5.接下来就是写一个测试activity调用我们的progressDialog了。
01 |
package com.lxd.activity;
|
02 |
03 |
import com.lxd.widgets.CustomProgressDialog;
|
04 |
05 |
import android.app.Activity;
|
06 |
import android.os.AsyncTask;
|
07 |
import android.os.Bundle;
|
08 |
import android.view.Window;
|
09 |
import android.view.WindowManager;
|
10 |
11 |
public class MainFrame extends Activity {
|
12 |
private MainFrameTask mMainFrameTask = null ;
|
13 |
private CustomProgressDialog progressDialog = null ;
|
14 |
|
15 |
@Override
|
16 |
public void onCreate(Bundle savedInstanceState) {
|
17 |
super .onCreate(savedInstanceState);
|
18 |
this .requestWindowFeature(Window.FEATURE_NO_TITLE);
|
19 |
this .getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
20 |
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
21 |
|
22 |
setContentView(R.layout.main);
|
23 |
|
24 |
mMainFrameTask = new MainFrameTask( this );
|
25 |
mMainFrameTask.execute();
|
26 |
}
|
27 |
|
28 |
@Override
|
29 |
protected void onDestroy() {
|
30 |
stopProgressDialog();
|
31 |
|
32 |
if (mMainFrameTask != null && !mMainFrameTask.isCancelled()){
|
33 |
mMainFrameTask.cancel( true );
|
34 |
}
|
35 |
|
36 |
super .onDestroy();
|
37 |
}
|
38 |
39 |
private void startProgressDialog(){
|
40 |
if (progressDialog == null ){
|
41 |
progressDialog = CustomProgressDialog.createDialog( this );
|
42 |
progressDialog.setMessage( "正在加载中..." );
|
43 |
}
|
44 |
|
45 |
progressDialog.show();
|
46 |
}
|
47 |
|
48 |
private void stopProgressDialog(){
|
49 |
if (progressDialog != null ){
|
50 |
progressDialog.dismiss();
|
51 |
progressDialog = null ;
|
52 |
}
|
53 |
}
|
54 |
|
55 |
public class MainFrameTask extends AsyncTask<Integer, String, Integer>{
|
56 |
private MainFrame mainFrame = null ;
|
57 |
|
58 |
public MainFrameTask(MainFrame mainFrame){
|
59 |
this .mainFrame = mainFrame;
|
60 |
}
|
61 |
|
62 |
@Override
|
63 |
protected void onCancelled() {
|
64 |
stopProgressDialog();
|
65 |
super .onCancelled();
|
66 |
}
|
67 |
68 |
@Override
|
69 |
protected Integer doInBackground(Integer... params) {
|
70 |
|
71 |
try {
|
72 |
Thread.sleep( 10 * 1000 );
|
73 |
} catch (InterruptedException e) {
|
74 |
e.printStackTrace();
|
75 |
}
|
76 |
return null ;
|
77 |
}
|
78 |
|
79 |
@Override
|
80 |
protected void onPreExecute() {
|
81 |
startProgressDialog();
|
82 |
}
|
83 |
84 |
@Override
|
85 |
protected void onPostExecute(Integer result) {
|
86 |
stopProgressDialog();
|
87 |
}
|
88 |
|
89 |
|
90 |
|
91 |
}
|
92 |
} |
- android_progressDialog.zip (48.6 KB)
- 下载次数: 127
评论
2 楼
骑蚂蚁闯江湖
2012-09-06
楼主 求那Animation-list中的几张图片啊 ! 能否发我邮箱357630106@qq.com 谢谢
1 楼
goonlove0
2012-06-22
您好,能否上传一下那几张progress图片.
发表评论
-
Dhdb 简化sqlite数据库操作--dhroid文档
2014-04-15 12:30 1309android数据库其实使用的不多,dhroid框架中的 ... -
dhroid ioc模块对 加密混淆问题
2014-04-14 12:52 921大家应该已经看过ioc ... -
NetJSONAdapter 网络化的adapter(高效) -dhroid文档
2014-04-04 12:15 843关于adapter 我想对于大家来说已经不陌生了,基本应用 ... -
DhNet 网络http工具(带缓存功能哦) -dhroid文档
2014-03-24 13:36 1401网络请求是大多数应用不可获取的一部分,曾经和一个其他公司的 ... -
eventbus 事件总线-dhroid文档
2014-03-23 11:47 1212你听过onClick 事件,onItemClick 事件, ... -
ioc基础(视图,资源,assert注入)-dhroid文档
2014-03-21 12:59 821上一节 Android 极速开发框架 dhroid来了 ... -
ioc高级(接口,对象注入)-dhroid文档
2014-03-21 13:04 1085前一章 ioc基础( ... -
IOC容器详解(想晋升的进来)---dhroid框架教教程(一)
2014-03-20 10:30 942控制反转(Inversion of Control,英文缩写 ... -
Android 极速开发框架 dhroid来了(提供demo)
2014-03-19 17:24 1338我们公司内部使用的商业级android开发框架dhr ... -
HttpClient的3种超时说明
2013-03-14 11:05 851/* 从连接池中取连接的超时时间 */ConnManag ... -
MeasureSpec介绍及使用详解
2013-01-24 21:21 728一个MeasureSpec封装了父 ... -
Android使用自定义AlertDialog
2012-12-28 11:48 799Android使用自定义AlertDialog以下的代码是写在 ... -
Android学习——TextView 设置中划线 下划线
2012-10-31 14:42 3431android:textAppearance ... -
ListView与其中的Button,EditText,RatingBar等widget的click事件
2012-10-26 14:48 812在<RelativeLayout>中 an ... -
Android PNG渐变背景图片失真问题
2012-09-13 15:06 722最近一个困扰很久的问题,渐变效果的png图片,设置为控件 ... -
在线词典API
2012-09-09 19:34 687QQ词典 http://dict.qq.com/dic ... -
关于android WebViewClient的方法解释
2012-09-09 17:12 7381、public boolean shouldOverride ... -
android Uri获取真实路径转换成File的方法
2012-08-23 12:40 3026data.getData()返回的 ... -
Java之WeakReference与SoftReference使用讲解
2012-08-22 09:46 648如果你想写一个 Java 程序,观察某对象什么时候会被垃圾收集 ... -
Android自定义捕获Application全局异常
2012-08-21 17:24 1146package qianlong.qlmobile ...
相关推荐
android 自定义progressDialog实现 加载转圈等待
Android中自定义ProgressDialog实现加载滚动条效果,例如显示“请稍后……”,希望对于有帮助
android 自定义ProgressDialog对话框,
android自定义ProgressDialog样式详解,一分钟教会你如何自定义android样式。
android 自定义组合progressdialog进度条,方便你的使用............................................................................................
Android中自定义ProgressDialog实现加载滚动条效果(例如:1.加载中…2.请稍后……等)
闲来无事,总结了两个自定义的ProgressDialog,大家可以参考下
详细请参考我的csdn博客:http://blog.csdn.net/allen315410/article/details/41699063
这个demo是关于android中继承Dialog重新自定义一个ProgressDialog。 需求:带加载图片和文字说明,可定时停止也可被动中断。 如有BUG或者不完善,欢迎小伙伴们提出~
主要介绍了Android自定义ProgressDialog系统加载框,通过本文大家可以尝试利用Android自定义ProgressDialog,感兴趣的小伙伴们可以参考一下
主要为大家详细介绍了android自定义ProgressDialog加载效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
有时我们在项目执行某些耗时的操作是需要在界面上给出等待之类的信息,在android里面可以使用progressbar或者progressdialog,但是...所以需要自定义一个progressdialog,这个小例子试下了简单的自定义progressdialog
自定义ProgressDialog 更加美观 主要用于耗时操作 比如网络请求等
主要介绍了实例详解Android自定义ProgressDialog进度条对话框的实现的相关资料,需要的朋友可以参考下
Android自定义类似ProgressDialog效果的Dialog
Android本身已经提供了ProgressDialog进度等待框,使用该Dialog,我们可以为用户提供更好的体验:在网络请求时,弹出此框等待网络数据。 不过,既然是为了提高用户体验,我们肯定希望该Dialog能更加炫酷,让用户看着...
自定义的很漂亮的Android ProgressDialog, 可以拿去修改一下,用在自己的项目中