Custom ProgressBar 모듈화(with Alert Dialog)

우왕이·2022년 8월 5일
0

Module.kt

목록 보기
2/4
post-thumbnail

Reason For Use

 기본 progressBar의 뒷 배경에 blur 처리를 위해 AlertDialog를 사용.

Module

/* Utile.kt */

fun customProgressBar(context: Context, layoutInflater: LayoutInflater): AlertDialog {
    val binding = DialogProgressbarBinding.inflate(layoutInflater)

    return AlertDialog.Builder(context)
        .setCancelable(false)
        .setView(binding.root)
        .show().apply {
            // 뒷 배경 blur 처리
            this.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }
}

/* dialog_progressbar.xml */

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    >

    <ProgressBar
        android:id="@+id/progress_bar"
        android:visibility="visible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintVertical_bias="0.4"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

Usage

/* SampleActivity.kt */

// progressBar 시작
val progressBar = customProgressBar(this@SampleActivity, layoutInflater)

// progressBar 종료
progressBar.dismiss()

ProgressBar With Alert Dialog

profile
우왕~

0개의 댓글