package com.zxhyis.toolss.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.WindowManager
import com.zxhyis.toolss.databinding.DialogManagerStorageSystemInBinding

class CustomDialog(val contexta: Context) : Dialog(contexta) {
    lateinit var binding: DialogManagerStorageSystemInBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DialogManagerStorageSystemInBinding.inflate(LayoutInflater.from(contexta))
        setContentView(binding.root)
        setCancelable(true)
        setCanceledOnTouchOutside(true)
        //修改dialog的尺寸
        val lp = window?.attributes
        lp?.width = ViewGroup.LayoutParams.MATCH_PARENT
        lp?.height = ViewGroup.LayoutParams.WRAP_CONTENT
        lp?.gravity = Gravity.CENTER
        window?.attributes = lp
        window?.setBackgroundDrawableResource(android.R.color.black)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
        } else {
            window?.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
        }
    }
}