loadingUtil
package com.coral3.common_module.utils;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.coral3.common_module.R;
public class LoadingUtil {
private static View loadingView;
private static ViewGroup contentView;
public static void startLoading(Context context){
if(null == contentView) contentView = ((Activity)context).findViewById(android.R.id.content);
if (loadingView == null) {
loadingView = LayoutInflater.from(context).inflate(R.layout.view_loading, null, false);
contentView.addView(loadingView);
} else {
loadingView.setVisibility(View.VISIBLE);
}
}
public static void hideLoading(){
if (loadingView != null) {
loadingView.setVisibility(View.GONE);
}
}
public static void startLoadingInUiThread(Context context){
((Activity)context).runOnUiThread(new Runnable() {
@Override
public void run() {
startLoading(context);
}
});
}
public static void hideLoadingInUiThread(Activity activity){
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
hideLoading();
}
});
}
}
view_loading.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/spin_kit"
style="@style/SpinKitView.Large.Circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/shape_loading_bg"
android:padding="20dp"
app:SpinKit_Color="@color/white" />
</RelativeLayout>