package com.zxhyis.tools.ui.dialog

import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.airbnb.lottie.LottieAnimationView
import com.zxhyis.tools.R

class LoadingDialog:DialogFragment() {

    private lateinit var loadVIew:View


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        loadVIew= inflater.inflate(R.layout.dialog_loading,container,false)
        return loadVIew
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val window = dialog?.window
        window?.setGravity(Gravity.CENTER)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val windowManager = activity?.windowManager
        val display = windowManager?.defaultDisplay
        val lp = dialog?.window!!.attributes
        lp.width = (display?.width!! * 0.3).toInt() //设置宽度
        dialog?.window!!.attributes = lp

        loadVIew.findViewById<LottieAnimationView>(R.id.lav_load).playAnimation()
    }


}