kotlin实现Dialog弹框

 val dialogContent = LayoutInflater.from(context).inflate(R.layout.dialog_delete_draft, null)
        val delete = dialogContent.findViewById(R.id.btn_delete)
        val cancel = dialogContent.findViewById(R.id.btn_cancel)
        val dialog = Dialog(context, R.style.ActionSheetDialogStyle)
        dialog.setContentView(dialogContent)
        dialog.window.setGravity(Gravity.CENTER)
        dialog.window.decorView.setPadding(0, 0, 0, 0)
        dialog.window.attributes.width = WindowManager.LayoutParams.WRAP_CONTENT
        dialog.window.attributes.height = WindowManager.LayoutParams.WRAP_CONTENT
        dialog.show()
        cancel.setOnClickListener {
            dialog.dismiss()
        }
        delete.setOnClickListener {
            onGet(HttpConstants.Note.DELETE_DRAFT_BY_ID, mapOf("noteId" to list[position].id))
            dialog.dismiss()
        }

资源文件

 

你可能感兴趣的:(Kotlin)