第三方效果圖:
第三方GitHub地址
https://github.com/hanzhanbing/AVLoadingIndicatorView
實(shí)際使用:
Step 1:
bulid.gradle
dependencies {
compile 'com.wang.avi:library:2.1.3'
}
Step 2:
dialog_loading.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/avi"
style="@style/AVLoadingIndicatorView.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:indicatorColor="#FF0000"
app:indicatorName="LineSpinFadeLoaderIndicator" />
</RelativeLayout>
Step 3:
style.xml
<style name="TransparentDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
Step 4:
LoadingDialog.java
/**
* 加載中Dialog
*
* @author hzb
*/
public class LoadingDialog extends AlertDialog {
private static LoadingDialog loadingDialog;
private AVLoadingIndicatorView avi;
public static LoadingDialog getInstance(Context context) {
loadingDialog = new LoadingDialog(context, R.style.TransparentDialog); //設(shè)置AlertDialog背景透明
loadingDialog.setCancelable(false);
loadingDialog.setCanceledOnTouchOutside(false);
return loadingDialog;
}
public LoadingDialog(Context context, int themeResId) {
super(context,themeResId);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog_loading);
avi = (AVLoadingIndicatorView)this.findViewById(R.id.avi);
}
@Override
public void show() {
super.show();
avi.show();
}
@Override
public void dismiss() {
super.dismiss();
avi.hide();
}
}
Step 5:
加載框顯示
LoadingDialog.getInstance(this).show();
加載框隱藏
LoadingDialog.getInstance(this).dismiss();
Step 6:
效果圖