自定义progressDialog~~~
来源:互联网 发布:excel如何将拆分数据 编辑:程序博客网 时间:2024/06/05 19:29
在等待某些请求时,如果什么都不做,会很枯燥,但是progressDialog的显示又比较丑,很多情况下都是使用自定义的效果显示,这里给大家转载一个方法。供大家学习。原文地址http://blog.csdn.net/lovewaterman/article/details/40079549
效果的话懒得截图 简单的说就是全屏显示一个圆形的进度条,当然这个可以根据自己的需求更换动画,例如百度贴吧那种小人快跑的效果。
代码如下
- 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>
然后就是 customprogressdialog的类 这里使用单例模式只需在使用时引用
package com.example.TrueLife.util;
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;
import com.example.TrueLife.R;
/**
* Created by Administrator on 2015/8/11.
*/
public class CustomProgressDialog extends Dialog{
private Context context;
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.start_img_loading);
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.start_tv_loading);
if (tvMsg != null){
tvMsg.setText(strMessage);
}
return customProgressDialog;
}
}
引用方法相信大家都会 如下:
显示
customProgressDialog = CustomProgressDialog.createDialog(StartActivity.this);
customProgressDialog.show();
取消显示
customProgressDialog.dismiss();
- 【progressDialog】自定义progressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- 自定义progressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- 自定义progressDialog
- 自定义progressDialog~~~
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- ProgressDialog自定义方法
- POJ 2456 Aggressive cows(二分)
- 找到并留住富有激情的问题解决者
- 8.12总结
- java ------ IO(从基础到加强)
- 数据解析
- 自定义progressDialog~~~
- 原码, 反码, 补码 详解
- hdu 5375 Gray code(dp)
- 第10章:深入函数
- zoj 3688
- 【Android性能优化】Android-Lint:查错与代码优化利器
- maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- group by的参考地址
- POJ-2187(旋转卡壳)