【Android自定义View实战】之自定义项目通用的加载等待对话框LoadingDialog
来源:互联网 发布:星际战甲怎么设置端口 编辑:程序博客网 时间:2024/05/14 15:13
转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/52971048 【DylanAndroid的csdn博客】
在平时的Android开发中,我们难免会遇到像登陆.注册.获取数据这样的操作,而用的的网络状况不同,导致操作需要等待一定的时间,那么为了友好期间,我们需要给用户提供一个在操作完之后的一个友好的等待界面,而Android系统自带的等待对话框比较难看,而且根据项目的不同,产品经理也会有不同的要求,或者客户有特殊的要求。所以,需要我们去自己自定义一个加载等待对话框。
下面我们来做一个给中石油做的一个App中的加载等待对话框。
1.先看效果图
2.准备资源文件
- 等待对话框的背景图片->loading_bg.9.png
- 等待对话框的旋转动画图片->loading.png
3.进度条动画旋转实现
custom_progress_draw.xml
<?xml version="1.0" encoding="utf-8"?><animated-rotatexmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@mipmap/loading"android:pivotX="50%"android:pivotY="50%"/>
4.自定义等待对话框的布局文件
- loading.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <RelativeLayout android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" android:gravity="center" android:background="@mipmap/loading_bg"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center|bottom" android:orientation="vertical"> <ProgressBar style="@android:style/Widget.ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminateDrawable="@drawable/custom_progress_draw" /> <TextView android:layout_marginBottom="20dp" android:id="@+id/tv_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="正在登录" android:layout_marginTop="20dp" android:textColor="#fff" /> </LinearLayout> </RelativeLayout></RelativeLayout>
5.自定义对话框代码:
package cn.bluemobi.dylan;import android.app.Dialog;import android.content.Context;import android.graphics.Color;import android.graphics.drawable.ColorDrawable;import android.widget.TextView;/** * 自定义加载进度对话框 * Created by Dylan on 2016-10-28. */public class LoadingDialog extends Dialog { private TextView tv_text; public LoadingDialog(Context context) { super(context); /**设置对话框背景透明*/ getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); setContentView(R.layout.loading); tv_text = (TextView) findViewById(R.id.tv_text); setCanceledOnTouchOutside(false); } /** * 为加载进度个对话框设置不同的提示消息 * * @param message 给用户展示的提示信息 * @return build模式设计,可以链式调用 */ public LoadingDialog setMessage(String message) { tv_text.setText(message); return this; }}
6.用法:一句代码搞定
MainActivity中
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new LoadingDialog(this).setMessage("正在加载...").show();}
7.再次看效果
8.GitHub地址:https://github.com/linglongxin24/LoadingDialog
5 0
- 【Android自定义View实战】之自定义项目通用的加载等待对话框LoadingDialog
- 【Android自定义View实战】之自定义项目通用的标题栏CustomTitleBar
- Android 的自定义等待对话框
- 自定义LoadingDialog
- 自定义LoadingDialog
- 自定义LoadingDialog
- 自定义LoadingDialog
- Android自定义view之环形等待控件的实现
- Android自定义view的实战
- 【Android自定义View实战】之仿百度加载动画,一种优雅的Loading方式
- Android自定义View之TitleBar,通用标题栏
- 【Android自定义View实战】之自定义圆形头像CircleImageView支持加载网络图片
- 加载对话框(LoadingDialog)
- Android--view自定义--圆环等待
- Android自定义加载对话框
- android 自定义view实战之switchButton
- 【Android自定义View实战】之你应该明白的事儿
- 你也可以自己写一个可爱 & 小资风格的Android加载等待自定义View
- 文章标题
- JavaScript中常见的HTML DOM操作
- centos7使用chrome在CSDN上传文件时,文本上传框被阻止的解决方法
- final修饰基本类型和引用类型变量的区别
- 极客 - 博文30 - 单链表的重新排列
- 【Android自定义View实战】之自定义项目通用的加载等待对话框LoadingDialog
- c++ 运行时多态
- linux
- Debug 和 Release的区别
- CSS 4.2 样式-文本
- 基本数据类型总结
- 汉字转换为拼音
- 多尺度空间
- StartUML_UML关系