日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android布局DSL,android – 使用自定义Anko布局DSL解除警报对话框

發布時間:2024/1/23 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android布局DSL,android – 使用自定义Anko布局DSL解除警报对话框 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我創建了以下警告對話框,其中包含一個包含TextView,EditText和Button的簡單視圖:

alert {

customView {

verticalLayout {

textView {

text = getString(R.string.enter_quantity)

textSize = 18f

textColor = Color.BLACK

}.lparams {

topMargin = dip(17)

horizontalMargin = dip(17)

bottomMargin = dip(10)

}

val quantity = editText {

inputType = InputType.TYPE_CLASS_NUMBER

background = ContextCompat.getDrawable(this@ProductsList, R.drawable.textbox_bg)

}.lparams(width = matchParent, height = wrapContent) {

bottomMargin = dip(10)

horizontalMargin = dip(17)

}

button(getString(R.string.confirm)) {

background = ContextCompat.getDrawable(this@ProductsList, R.color.colorPrimary)

textColor = Color.WHITE

}.lparams(width = matchParent, height = matchParent) {

topMargin = dip(10)

}.setOnClickListener {

if (quantity.text.isNullOrBlank())

snackbar(parentLayout!!, getString(R.string.enter_valid_quantity))

else

addToCart(product, quantity.text.toString().toInt())

}

}

}

}.show()

我想在單擊按鈕并執行if-else子句時忽略它.我嘗試使用這個@ alert但它沒有提供對話框方法.

解決方法:

這是有問題的,因為當對話框尚不存在時,您的按鈕函數調用會注冊偵聽器.

這是一種方法,使用本地lateinit變量使對話框在偵聽器中可用:

lateinit var dialog: DialogInterface

dialog = alert {

customView {

button("Click") {

dialog.dismiss()

}

}

}.show()

您還可以將構建器的結果分配給類屬性等.請注意,局部變量的lateinit可用于since Kotlin 1.2.

標簽:anko,android,kotlin

來源: https://codeday.me/bug/20190727/1550077.html

總結

以上是生活随笔為你收集整理的android布局DSL,android – 使用自定义Anko布局DSL解除警报对话框的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。