android 键盘偶现收起之后又弹出
生活随笔
收集整理的這篇文章主要介紹了
android 键盘偶现收起之后又弹出
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
現(xiàn)象:應(yīng)用首次安裝,點擊搜索。彈起鍵盤。退出應(yīng)用,鍵盤收起又彈出
fun hideSoftKeyboard(editText: EditText?) {if (editText != null) {val imm = editText.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManagerimm.hideSoftInputFromWindow(editText.windowToken, 0)}}fun showSoftKeyboard(editText: EditText?) {if (editText != null) {val imm = editText.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManagerimm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0)}}原因:
可能是使用了toggleSoftInput方法導(dǎo)致的,show和hide要成對使用,官方不建議使用toggleSoftInput。
解決方案:
fun hideSoftKeyboard(editText: EditText?) {if (editText != null) {val imm = editText.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManagerimm.hideSoftInputFromWindow(editText.windowToken, 0)}}fun showSoftKeyboard(editText: EditText?) {if (editText != null) {val imm = editText.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManagerimm.showSoftInput(editText,0)}}總結(jié)
以上是生活随笔為你收集整理的android 键盘偶现收起之后又弹出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 进阶博弈论 Advanced Game
- 下一篇: L1-068 调和平均 (10 分)