Android loading Dialog 自定义
2016-07-06 18:24
405 查看
看到IOS端做了这个加载数据的效果,为了保持UI一致,就自定义了Loading Dialog !
先看一下大概的效果:
下面就是代码部分:
res/drawable/
Dialog主要布局:
layout/
主要代码部分:
java:
Activity:
java:
先看一下大概的效果:
下面就是代码部分:
res/drawable/
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="20" android:useLevel="false" > <gradient android:centerColor="@color/colorAccent" // 主题控件颜色,可以根据需要给定 android:centerY="0.50" android:endColor="@color/colorAccent" android:startColor="#00ffffff" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
Dialog主要布局:
layout/
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_dialog" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="15dp" android:paddingRight="25dp" android:paddingLeft="25dp" android:paddingBottom="5dp" android:gravity="center"> <ProgressBar android:id="@+id/pb_progress_bar" android:layout_width="50dp" android:layout_height="50dp" android:indeterminateDrawable="@drawable/progressbar" android:indeterminateDuration="700" android:visibility="visible" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="7dp" android:text="New Text" android:id="@+id/tv_loading" android:layout_gravity="center_horizontal" /> </LinearLayout>
主要代码部分:
java:
/** * * @param context * @param isAlpha 是否需要透明度 * @param message 显示加载的内容 * @return */ public static Dialog writeDialog(Context context,boolean isAlpha,String message){ Dialog progressDialog = new Dialog(context); progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); if (isAlpha){ WindowManager.LayoutParams lp= progressDialog.getWindow().getAttributes(); lp.alpha=0.8f; progressDialog.getWindow().setAttributes(lp); } LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.dialog, null); LinearLayout layout = (LinearLayout) v.findViewById(R.id.ll_dialog); ProgressBar pb_progress_bar = (ProgressBar) v.findViewById(R.id.pb_progress_bar); pb_progress_bar.setVisibility(View.VISIBLE); TextView tv = (TextView) v.findViewById(R.id.tv_loading); if (message==null||message.equals("")){ tv.setVisibility(View.GONE); }else{ tv.setText(message);
//R.color.colorAccent 我是拿的主题控件颜色,可以根据需要给tv.setTextColor(context.getResources().getColor(R.color.colorAccent)); } progressDialog.setContentView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); return progressDialog;}
Activity:
java:
progressDialog = DialogUtil.writeDialog(this,false,"正在加载"); progressDialog.show(); progressDialog.setCanceledOnTouchOutside(false);//设置点击屏幕加载框不会取消(返回键可以取消)
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories