不需要Activity的AlertDialog

 private fun loadingAlertDialog() {
        var layoutParams: WindowManager.LayoutParams? = null
        val inflate = View.inflate(FontsApp.instance, R.layout.layer_lock_dialog, null)
        val builder = AlertDialog.Builder(FontsApp.instance, R.style.Translucent_NoTitle)
                .setView(inflate)
       val create =  builder.create()
        inflate.findViewById(R.id.iv_unlock).setOnClickListener {
            create.dismiss()

        }
        //rootView顶层View获取windowToken
        val windowToken: IBinder? = rootView?.windowToken
        val window = create.window
        layoutParams = window?.attributes
        layoutParams?.token = windowToken
        layoutParams?.type = 1000
        window?.attributes = layoutParams
        window?.addFlags(WindowManager.LayoutParams.ALPHA_CHANGED)
        create.show()

    }

你可能感兴趣的:(lotlin相关,速记)