在方向更改时保留软输入/IME状态 [英] Retain soft-input/IME state on Orientation change

查看:91
本文介绍了在方向更改时保留软输入/IME状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序出现小用户体验问题;

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).

我一直在寻找答案,似乎在Activity清单中的windowSoftInputMode选项中添加stateUnchanged是解决此问题的正确方法(如

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.

有人知道对此功能有任何警告吗?如果焦点所在的EditText位于Fragment中,可能不起作用?

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

推荐答案

将其添加到您的代码中即可使用:

Add this to your code and it will work :

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

这篇关于在方向更改时保留软输入/IME状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆