1、首先准备好图片资源,写一个自定义的drawable(progress_drawable_white),实现动画功能。

<?xml version="1.0" encoding="utf-8"?><animation-list android:oneshot="false"                xmlns:android="http://schemas.android.com/apk/res/android">    <item android:duration="83" android:drawable="@drawable/ic_loading_white_01" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_02" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_03" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_04" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_05" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_06" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_07" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_08" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_09" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_10" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_11" />    <item android:duration="83" android:drawable="@drawable/ic_loading_white_12" /></animation-list>

2、布局文件是少不了的,接着。。。(dialog_my)

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:background="@drawable/ic_loading_bg"              android:gravity="center"              android:orientation="vertical"              android:padding="16.0dip" >    <ProgressBar            android:layout_width="30.0dip"            android:layout_height="30.0dip"            android:indeterminateDrawable="@drawable/progress_drawable_white" />    <TextView            android:id="@+id/id_tv_loadingmsg"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_vertical"            android:layout_marginTop="8.0dip"            android:textColor="#fff"            android:textSize="16.0dip" /></LinearLayout>
3、res包下values包需要之定义style(style_dialog)
<?xml version="1.0" encoding="utf-8"?><resources>    <style name="progress_dialog" parent="@android:style/Theme.Dialog">        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowIsTranslucent">true</item>        <item name="android:windowNoTitle">true</item>        <item name="android:background">@null</item>        <item name="android:windowBackground">@null</item>        <item name="android:backgroundDimEnabled">false</item>    </style></resources>

4、BaseActivity中书写公共的方法,以后项目中所有的Activity只要继承BaseActivity,只需调用方法就行了。加载提示的内容我写了两种,可以这样用,十分方便。

package com.sunday.myprogresdialog;import android.app.Activity;import android.app.Dialog;import android.os.Bundle;import android.widget.TextView;public class BaseActivity extends Activity {private Dialog progressDialog;/** * Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);}/** *  * @Description: TODO 自定义加载提示内容 * @param @param id * @return void 用法buildProgressDialog(R.string.loding) * @throws * @author Sunday * @date 2015年12月25日 */public void buildProgressDialog(int id) {if (progressDialog == null) {progressDialog = new Dialog(this, R.style.progress_dialog);}progressDialog.setContentView(R.layout.dialog_my);progressDialog.setCancelable(true);progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);msg.setText(getString(id));progressDialog.show();}/** * @Description: TODO 固定加载提示内容 * @author Sunday */public void buildProgressDialog() {if (progressDialog == null) {progressDialog = new Dialog(this, R.style.progress_dialog);}progressDialog.setContentView(R.layout.dialog_my);progressDialog.setCancelable(true);progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);msg.setText("卖力加载中");progressDialog.show();}/** * @Description: TODO 取消加载框 * @author Sunday * @date 2015年12月25日 */public void cancelProgressDialog() {if (progressDialog != null) {progressDialog.dismiss();}}}

5、只需调用buildProgressDialog()和cancelProgressDialog()就能实现加载和取消了。


项目效果图


项目下载地址

MyProgressDialog

更多相关文章

  1. Android(安卓)SwipeRefreshLayout+RecyclerView下拉刷新与上拉加
  2. [Android--Tool]提示adb is down问题与解决
  3. android:WebView在没有网络情况下,点击当前页面内链接不跳转并弹
  4. 原生Android应用中内嵌RN
  5. Android个推使用
  6. android webview 加载本地文件
  7. android应用程序启动解决黑屏及全屏显示时因数据加载缓慢出现标
  8. android webview的 一些设置(js java交互)
  9. Android中VideoView播放视频不能充满屏幕以及视频上的view与视频

随机推荐

  1. Android(安卓)基于google Zxing实现二维
  2. Android系统启动流程 -- android
  3. Android之activity属性汇总
  4. 2011年Android产品趋势
  5. 配置并使用Android支持的库
  6. Android术语小全,推荐一下(改日在翻译).
  7. Android(安卓)EditText 一些属性设置
  8. Android(安卓)体系结构介绍
  9. Android笔记 - 常见错误解决方法 | Andro
  10. Android知识点