Android中自定义ProgressDialog实现加载滚动条(加载中…)效果
来源:互联网 发布:网络主播签约合同 编辑:程序博客网 时间:2024/05/17 08:17
本文所述是通过自定义ProgressDialog实现弹出“加载中……”,效果如下图:
1、xml布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_dialog_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00000000" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/round_bg" android:gravity="center" android:padding="10dp" android:orientation="horizontal"> <ImageView android:id="@+id/dialog_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/loading"/> <TextView android:id="@+id/dialog_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:text="@string/dialog_txt" android:textSize="12sp" android:textColor="@color/colorDialogTxt"/> </LinearLayout></LinearLayout>
2、自定义ProgressDialog
public class MyProgressDialog extends ProgressDialog { private static ProgressDialog progressDialog; public MyProgressDialog(Context context){ super(context); } public MyProgressDialog(Context context,int theme){ super(context, theme); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = LayoutInflater.from(getContext()); // 得到加载view View v = inflater.inflate(R.layout.myprogressdialog, null); // 加载布局 LinearLayout layout = (LinearLayout) v.findViewById(R.id.ll_dialog_view); // ImageView控件 ImageView dialogImage = (ImageView) v.findViewById(R.id.dialog_img); // 加载动画 Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.dialog); // 显示动画 dialogImage.startAnimation(animation); //为显示dialog的圆角,不加会出现四个黑棱角 getWindow().setBackgroundDrawable(new BitmapDrawable()); setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); } public static void showDialog(Context context,String msg){ progressDialog=new MyProgressDialog(context, R.style.dialogBoxTheme); progressDialog.setCancelable(false);// 不可以用“返回键”取消 progressDialog.setCanceledOnTouchOutside(false);//不可点击进度框外部取消 progressDialog.setMessage(msg); progressDialog.show(); } public static void closeDialog(){ if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); progressDialog = null; } }}
3、进度条样式主题
<?xml version="1.0" encoding="utf-8"?><resources> <!--dialog主题--> <style name="dialogBoxTheme" parent="@android:style/Theme.Dialog"> <!--背景--> <item name="android:background">#00000000</item> <!--边框--> <item name="android:windowFrame">@null</item> <!--是否浮现在activity之上--> <item name="android:windowIsFloating">true</item> <!--半透明--> <item name="android:windowIsTranslucent">true</item> <!--标题--> <item name="android:windowNoTitle">true</item> <!--模糊--> <item name="android:backgroundDimEnabled">false</item> <!--字体颜色--> <item name="android:textColor">@color/colorDialogTxt</item> <item name="android:windowBackground">@null</item> </style></resources>
//显示加载中...LoadingDialog.showLoading(this,"加载中...");在执行你的程序之前加上上面一句,即可显示加载中……对话框。
LoadingDialog.closeLoading();程序执行完后调用上面一句即可关闭。
5、源码
地址:http://download.csdn.net/detail/coderk2014/9663225
0 0
- Android中自定义ProgressDialog实现加载滚动条(加载中…)效果
- Android自定义类似ProgressDialog效果加载动画
- 滚动加载条效果
- Android自定义progressDialog实现loading载中动画效果
- Android自定义progressDialog实现 loading 载入中 动画效果
- Android中自定义ProgressDialog,实现全屏显示的效果
- android中自定义progressDialog实现
- 实现圆形加载中效果自定义Dialog
- Android中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- ANDROID中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- Android中自定义的加载对话框和加载条
- Android中实现延迟加载效果
- android实现加载等待ProgressDialog
- Android 自定义加载中
- Android中实现加载样式图片自定义
- 安卓开发加载中效果类似progressDialog效果加载动画
- Xcode8系统log删除
- 很快的maven镜像。
- bzoj4197[Noi2015]寿司晚宴 [状压DP]
- 解决 oracle查询时char类型为character只显示一个字符的问题
- 第八周Raptor练习--矩形的面积
- Android中自定义ProgressDialog实现加载滚动条(加载中…)效果
- 转 Centos7下使用Squid快速搭建带认证的HTTP代理服务器
- Maven deploy跳过某个module解决办法
- iOS 10中如何搭建一个语音转文字框架
- VS OpenSSL 环境配置
- 进程通信
- iOS10适配:被弃用的openURL
- 了解 Spring Data JPA
- 管理后台 - 轮播图片管理功能