安卓设置EditText获取焦点并弹出软键盘及手动关闭软键盘

版权声明:本文为程序园中猿原创文章,转载请注明出处 https://blog.csdn.net/yinxing2008/article/details/88899157
  1. 设置EditText获取焦点并弹出软键盘
private fun showSoftInput(activity: Activity, editText: EditText) {
    editText.requestFocus()
    activity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
}
  1. 手动关闭软键盘
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://blog.csdn.net/yinxing2008/article/details/84555061
更多技术总结好文,请关注:「程序园中猿」

猜你喜欢

转载自blog.csdn.net/yinxing2008/article/details/88899157