自定义ProgressDialog 博客2
来源:互联网 发布:淘宝客服需要会哪些 编辑:程序博客网 时间:2024/05/20 21:47
算是半改这篇文章吧,稍作修改,有不足之处,还请指正
纯转载不运行的事我不干,我的博客都是能运行的东西,不想让人看了没结果
http://blog.csdn.net/yeqishi/article/details/7622023
看看效果图
Android系统自带的ProgressDialog样式的确不太好看,我们可以自己定义它的样式,下面看看实现
1.style.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">@drawable/toast_frame</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"
- android:padding="8dp" >
- <ProgressBar
- android:id="@+id/loadingImageView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="15dp"
- android:indeterminateDrawable="@drawable/progress_medium" />
- <TextView
- android:id="@+id/id_tv_loadingmsg"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:textColor="@android:color/white"
- android:textSize="18dp" />
- </LinearLayout>
3.progress_medium.xml文件.旋转效果。
- <?xml version="1.0" encoding="utf-8"?>
- <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/spinner_black_32"
- android:fromDegrees="0"
- android:pivotX="50.0%"
- android:pivotY="50.0%"
- android:toDegrees="360" />
4.CustomProgressDialog.java文件,这个是就是我们最终需要使用的progressDialog了。
- package com.xxx.view;
- import com.xxx.activity.R;
- import android.app.Dialog;
- import android.content.Context;
- import android.view.Gravity;
- import android.widget.TextView;
- public class CustomProgressDialog extends Dialog {
- public CustomProgressDialog(Context context, String strMessage) {
- this(context, R.style.CustomProgressDialog, strMessage);
- }
- public CustomProgressDialog(Context context, int theme, String strMessage) {
- super(context, theme);
- this.setContentView(R.layout.customprogressdialog);
- this.getWindow().getAttributes().gravity = Gravity.CENTER;
- TextView tvMsg = (TextView) this.findViewById(R.id.id_tv_loadingmsg);
- if (tvMsg != null) {
- tvMsg.setText(strMessage);
- }
- }
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- if (!hasFocus) {
- dismiss();
- }
- }
- }
我修改的部分也就主要是这里,之前作者用静态方法去构造ProgressDialog,context无法释放,下面是我修改后的代码
在Activity里面构造showProgressDialog:我写在自己的父类里
- public void showProgress(int resID, boolean canBack) {
- if (progressDialog != null) {
- progressDialog.cancel();
- }
- progressDialog = new CustomProgressDialog(activity, getResources()
- .getString(resID));
- progressDialog.show();
- }
子类继承调下这个方法就show出来了。
0 0
- 自定义ProgressDialog 博客2
- 自定义ProgressDialog 博客1
- 自定义ProgressDialog 博客3
- 【progressDialog】自定义progressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- 自定义progressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- 自定义progressDialog
- 自定义progressDialog~~~
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义ProgressDialog
- 自定义progressdialog
- Windows查看SID
- Eclipse 中 program arguments 与 VM arguments 的区别
- 近期遇到的一些问题及解决方法(11-24)
- (六)Intellij 中的蜡笔黄--警告
- Debug方法
- 自定义ProgressDialog 博客2
- sql loader的用法简介
- 如何在透明视图上显示不透明的子视图
- PCL环境配置迁移指南
- CityEngine CGA语法之尺寸函数 s(scope size)
- iOS开发 底层抛析运行循环—— RunLoop
- Java的委托
- 产品设计流程及UI设计注意事项
- Eclipse中Server视图加载项目之后项目名后边有带括号的名字