[activity_loading_hud.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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#00000000">

    <com.airbnb.lottie.LottieAnimationView
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:lottie_rawRes="@raw/loading_loop"  <!-- Lottie File -->
        app:lottie_loop="true"
        app:lottie_autoPlay="true" />


</RelativeLayout>

 

build.gradle 추가

implementation 'com.airbnb.android:lottie:6.3.0'

 

[LoadingHUD.java]

public class LoadingHUD extends Dialog {


    public LoadingHUD(@NonNull Context context) {
        super(context);

        setContentView(R.layout.activity_loading_hud);
        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setCancelable(false);
    }

    public LoadingHUD(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(R.layout.activity_loading_hud);
        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setCancelable(false);
    }

    protected LoadingHUD(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }
}

 

[사용방법]

LoadingHUD loadingHUD = new LoadingHUD(this);

// 노출

loadingHUD.show();

// 해제

loadingHUD.dismiss();

+ Recent posts