Advertisement

Responsive Advertisement

Make Your Own Custom Loader With Progress bar and imageview in kotlin

 First of all you  have to create kotlin object class and have to paste,
where loading1.xml and loading2.xml are:-
loading 1:-  
  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="@dimen/_68sp"
    android:layout_height="@dimen/_68sp"
    android:indeterminate="true"
    android:indeterminateTint="#F86202" />

    <ImageView
    android:layout_width="@dimen/_50sp"
    android:layout_height="@dimen/_50sp"
    android:layout_gravity="center"
    android:src="@drawable/logo_circle" />
    </FrameLayout>


    </LinearLayout>

  • loading 2 xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">


    </LinearLayout>

  • Main Loader.kt file

object Loading {
private var dialog: Dialog? = null

fun showHide(context: Context, it: Boolean) {
if (it) show(context) else dismiss()
}

fun showHide2(context: Context, it: Boolean) {
if (it) show2(context) else dismiss()
}

fun dismiss() {
dialog?.dismiss()

}

fun show(context: Context) {
dismiss()
dialog = Dialog(context)
dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog?.setCancelable(false)
dialog?.setContentView(R.layout.loading1)
val window = dialog?.window
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog?.show()
}

fun show2(context: Context) {
dismiss()
dialog = Dialog(context)
dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog?.setCancelable(false)
dialog?.setContentView(R.layout.loading2)
val window = dialog?.window
window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog?.show()
}

Post a Comment

0 Comments