- 设置EditText获取焦点并弹出软键盘
private fun showSoftInput(activity: Activity, editText: EditText) {
editText.requestFocus()
activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
}
- 手动关闭软键盘
private fun hideSoftInput(activity: Activity) {
var view = activity.currentFocus
if (view == null) {
view = View(activity)
}
val inputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0)
}
安卓开发技术分享: https://www.jianshu.com/p/442339952f26
更多技术总结好文,请关注:「程序园中猿」

网友评论