我的应用程序中使用了各种编辑文本、文本视图和列表视图。现在我的问题是当设备方向改变时,我的键盘会再次出现。理想情况下,当用户最小化键盘时,设备倾斜时键盘应该保持最小化状态,但它会重新出现。我们该如何处理这种情况。
我的另一个问题是我的某个编辑文本位于屏幕末尾。当键盘出现时,它会隐藏编辑文本,因此用户无法看到他正在输入什么。如何处理这种情况是最理想的方式。 谢谢。
解决所有问题的方法是这一行代码:android:windowSoftInputMode="stateUnchanged|adjustResize"
"stateUnchanged"将使键盘状态与先前状态相同,无论是隐藏还是显示。
"adjustResize"将使您的编辑文本可见。
希望这有所帮助!!!
编辑
需要将此添加到Android清单文件中。
我曾经遇到过这个问题。如果你有TextViews,并且想在旋转屏幕时避免键盘重新出现,你需要做两件事情-
Make sure the TextView doesn't have the focus. Even after hiding the keyboard, a TextView can still be focused. Try calling
textView.clearFocus()
and you should be able to see the difference in the TextView.
Make sure there is another view before it (like a parent LinearLayout, or even just a LinearLayout with 0 width and 0 height) which has these properties-
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden|adjustPan"
喜欢
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateHidden|adjustPan" >