Retain soft-input/IME state on Orientation change

时间秒杀一切 提交于 2019-12-12 11:14:01

问题


I'm having a small user experience issue in my app;

When changing from landscape to portrait (or portrait to landscape) with the Soft Keyboard open, the keyboard hides.

What I want to do is to stop the keyboard hiding on orientation change.

(Edit - I don't want to force the keyboard open, if the keyboard was hidden before the orientation change, I want it to stay hidden - I want to retain the keyboards open/closed state).

I've looked around for an answer and it seems adding stateUnchanged to the windowSoftInputMode options in the manifest for the Activity is the correct way to solve this (as described in the android documentation:

android:windowSoftInputMode="stateUnchanged|adjustResize" 

The problem is this seems to have absolutely no effect.

Does anybody know of any caveats to this functionality? Does it perhaps not work if the EditText which is focused is in a Fragment?


回答1:


Add this to your code and it will work :

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


来源:https://stackoverflow.com/questions/18182749/retain-soft-input-ime-state-on-orientation-change

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