gpt4 book ai didi

android - editText 处于焦点,但虚拟键盘不会在 Alert Builder 中使用 SHOW IMPLICIT 自动打开

转载 作者:行者123 更新时间:2023-11-29 02:22:19 25 4
gpt4 key购买 nike

当我使用 SHOW_FORCED 时键盘打开,但是当我关闭 alertDialog 时,键盘变为文本布局并且不隐藏,键盘仅在按下android的后退按钮时关闭,代码中模拟后退按钮不起作用。

并且使用 SHOW_IMPLICIT 不会自动打开键盘。

***注释代码有效但是...

private fun insertItemQuantity(orderDetail: OrderDetail) {
val modal = alert {
customView {
verticalLayout {
title = getString(R.string.insert_quantity)
val quantity = editText {
keyListener = DigitsKeyListener.getInstance("0123456789")
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or
InputType.TYPE_NUMBER_FLAG_SIGNED
showSoftInputOnFocus = true
isFocusable = true
isFocusableInTouchMode = true
}
positiveButton(getString(R.string.confirm)) {
val c = quantity.text.toString()
if (c.isBlank() )
toastCustomWarning(getString(R.string.field_cannot_be_empty))
else {
if (c.toDouble() > 0) {
RealmRepository.getRealm().beginTransaction()
orderDetail.quantity = c.toDouble()
orderDetail.uuid = UUID.randomUUID().toString()
RealmRepository.getRealm().commitTransaction()
orderItemActivityViewModel.addOrderItem(orderDetail)
} else {
toastCustomWarning(getString(R.string.field_cannot_be_empty_or_zero))
}
}
}
negativeButton(getString(R.string.cancel)) {
quantity.clearFocus()
}
neutralPressed("Neutral"){

}
}
}
}

//quantity.requestFocus()
/*val inputManager: InputMethodManager =
getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.toggleSoftInput(
InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY
)*/
var inputMethodManager: InputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(quantity, InputMethodManager.SHOW_IMPLICIT)
//inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
modal.iconResource = R.drawable.ic_logo
modal.show()
}

最佳答案

我不确定如何打开键盘,但您可以使用这种方法来隐藏键盘。我工作得很好。

(getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)
?.hideSoftInputFromWindow(findViewById<View>(android.R.id.content)?.windowToken, 0)

关于android - editText 处于焦点,但虚拟键盘不会在 Alert Builder 中使用 SHOW IMPLICIT 自动打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54610599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com