Warning : Do not use android:onClick Event in Layout XML File When Use Dialog
val mDialogBinding: LayoutBasicBinding = DataBindingUtil.inflate(getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater, R.layout.layout_basic, null, false)
var mDialog = Dialog(mActivity)
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
mDialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
mDialogBinding.btnClose.setOnClickListener {v ->
mDialog.dismiss()
}
mDialog.setContentView(mDialogBinding.root)
mDialog.setCancelable(true)
mDialog.show()
mDialogBinding.btnSubmit.setOnClickListener {v ->
var content = (mDialogBinding.submitContent as EditText).text.toString()
}
fun getDisplayMetrics() {
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics
}
fun getWidthPixels() {
var displayMetrics = getDisplayMetrics()
val displayWidth = displayMetrics.widthPixels
return displayWidth
}
fun getWidthPixels() {
var displayMetrics = getDisplayMetrics()
val displayWidth = displayMetrics.heightPixels
return displayWidth
}
fun getWindowAttributes(mDialog: Dialog) {
return mDialog.window!!.attributes
}
fun getWindowWidth(mDialog: Dialog) {
return getWindowAttributes(mDialog).width
}
fun getWindowHeight(mDialog: Dialog) {
return getWindowAttributes(mDialog).height
}
var params = getWindowAttributes(mDialog)
params.width = getWindowWidth(mDialog)
params.height = getWindowHeight(mDialog)
mDialog.window!!.attributes = params
var params = getWindowAttributes(mDialog)
params.width = WindowManager.LayoutParams.WRAP_CONTENT
params.height = WindowManager.LayoutParams.MATCH_PARENT
mDialog.window!!.attributes = params