关闭软键盘返回上一层界面导致界面卡顿

引起键盘关闭时界面卡顿,需在AndroidManifest.xml的<activity>中添加android:windowSoftInputMode="adjustNothing"

AndroidManifest.xml

android:windowSoftInputMode="adjustNothing"

打开软键盘

    /**
     * 获得焦点并弹出键盘
     */
    fun showSoftInputFromWindow(editText: EditText) {
        editText.isFocusableInTouchMode = true
        editText.requestFocus()
        val inputManager = editText.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
        inputManager?.showSoftInput(editText, 0)
    }

关闭软键盘

    /**
     * 关闭软键盘
     */
    fun closeSoftInput(){
        val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
        imm?.hideSoftInputFromWindow(view?.windowToken,0)  //界面跳转,关闭键盘
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容