How do I remove the keyboard after I finish an activity?

走远了吗. 提交于 2019-12-22 04:12:57

问题


I have an activity that users type inside and then click the ok button. When it is finished, the activity closes and goes back to the old activity but the soft keyboard is still on the screen! I've tried android:windowSoftInputMode="stateHidden" and

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

But it does nothing.


回答1:


In OnPause of your activity, you should do the following

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(et.getWindowToken(), 0);

Where et is an instance of your EditText.



来源:https://stackoverflow.com/questions/7339515/how-do-i-remove-the-keyboard-after-i-finish-an-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!