Android透明无边框圆形进度条之最简单实现

摘要:
很多人在项目中做长时间操作时,比如访问webservice后台数据,都想显示一个透明无边框的圆形进度条,如下图:不幸的是,Android系统自带的ProgressDialog,无论如何设置Theme、style,或者用java代码设置什么属性,边框都是去不掉的,至少我现在还不知道怎么去掉:怎么办?其实很简单,自定义一个ProgressDialog,加载自己的layout!new一个CustomProgressDialog实例,然后调用继承来的show()方法也行,直接使用我们上面定义的静态show()方法也可,看个人偏好。

很多人在项目中做长时间操作时,比如访问web service后台数据,都想显示一个透明无边框的圆形进度条,如下图:

Android透明无边框圆形进度条之最简单实现第1张

不幸的是,Android系统自带的ProgressDialog,无论如何设置Theme、style,或者用java代码设置什么属性,边框都是去不掉的,至少我现在还不知道怎么去掉:

Android透明无边框圆形进度条之最简单实现第2张

怎么办?

其实很简单,自定义一个ProgressDialog,加载自己的layout!

先上layout xml:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
3 &nbsp;&nbsp; &nbsp;android:layout_width="wrap_content"
4 &nbsp;&nbsp; &nbsp;android:layout_height="wrap_content"
5 &nbsp;&nbsp;&nbsp; android:interpolator="@android:anim/linear_interpolator" />

android:interpolator="@android:anim/linear_interpolator"这句话表示进度条动画是匀速的。

再来定义一个CustomProgressDialog:

1 public class CustomProgressDialog extendsProgressDialog{
2 
3     publicCustomProgressDialog(Context context) {
4         super(context);
5 }
6     
7     public CustomProgressDialog(Context context, inttheme) {
8         super(context, theme);
9 }
10 
11 @Override
12     protected voidonCreate(Bundle savedInstanceState) {
13         super.onCreate(savedInstanceState);
14 setContentView(R.layout.dialog_progress);
15 }
16     
17     public staticCustomProgressDialog show(Context ctx){
18         CustomProgressDialog d = newCustomProgressDialog(ctx);
19 d.show();
20         returnd;
21 }
22 }

至于怎么用这个Dialog,就不用我教了吧。new一个CustomProgressDialog实例,然后调用继承来的show()方法也行,直接使用我们上面定义的静态show()方法也可,看个人偏好。

有几点需要说明一下:

1. 也可以继承AlertDialog,效果一样。

2. 虽然我们在onCreate()方法里已经加载了自己的layout,但并不妨碍调用基类的方法,设置title、content,效果和直接用基类ProgressDialog一样,无视自定义。

easy?本文只是提供一个最简单实现,相信已经能满足大部分的需求了,更深入的东西自己摸索去吧。

免责声明:文章转载自《Android透明无边框圆形进度条之最简单实现》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇在Android上常用的定时器 AlarmManagerandroid SQLite使用SQLiteOpenHelper类对数据库进行操作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

歌词的获取

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_...

29Spring_Autowriter的一些疑惑(很重要)

我用一个Autowriter去注解一个属性,而且我没有在Spring的配置文件中的bean.xml中注册bean(<bean id=""...);那么这个注解有用吗?答案是不行。也就是说要用Autowriter注解时,其实必须要保证在bean容器中注册过这个bean. bean在bean容器中的注册分为两种: 1.手动:就是在spring.xml配置...

java 策略模式

定义:定义一组算法,将每个算法都封装起来,并且使他们之间可以互换。 类型:行为类模式 类图:        策略模式是对算法的封装,把一系列的算法分别封装到对应的类中,并且这些类实现相同的接口,相互之间可以替换。在前面说过的行为类模式中,有一种模式也是关注对算法的封装——模版方法模式,对照类图可以看到,策略模式与模版方法模式的区别仅仅是多了一个单独的封装...

android绘图—Paint path 旋转

http://meteor6789.blog.163.com/blog/static/35040733201111193535153/ Piant 看一段代码: mPaint = new Paint();mPaint.setAntiAlias(true);//锯齿mPaint.setDither(true);//mPaint.setColor(0xFF3...

Activity的生命周期详讲及其的生命周期监视,应用程序启动过程,

1:应用程序的启动过程 应用程序的图标被点击-》启动activitythread-》线程的入口main函数-》创建activitythread-》绑定activitythread thread.attach(false,startSeq)-》创建仪表类生命周期,管理程序的生命进程mInstrumentation = new Instrumentation(...

【aspnetcore】在过滤器(Filter)中使用注入服务(ServiceFilter|TypeFilter)

在MVC中,AOP是很常用的功能,我们经常会使用如 ActionFilter,IAuthorizeFilter 等描述对Controller和Action进行约束和扩展,一般做法如下: public class TestActionFilterAttribute : Attribute, IActionFilter { public voi...