Android - 当键盘弹出时如何调整屏幕?

7
我想在 Android 上调整我的 UI 屏幕,当软键盘弹出时。

目前我有类似于下面第一张图片的东西,在屏幕底部有一个 EditText,当用户点击 EditText 时,我希望出现第二张图片中发生的事情。

也就是说,EditText 被移动并出现在软键盘的顶部,当软键盘消失时,它应该返回到先前的状态。

有人可以告诉我最好的方法来处理和实现这个问题吗?

alt text http://img40.imageshack.us/img40/2300/keyboarddown.png


备用文字 http://img46.imageshack.us/img46/9339/keyboardup.png

(Note: This is not a complete sentence and may require more context to provide an accurate translation.)
3个回答

15
您需要在AndroidManifest.xml文件中的 标记中添加android:windowSoftInputMode="adjustResize"

在哪个标签中?我认为是<activity>标签,但它没有起作用。请回复。 - Anas Azeem
是的,它应该放在activity标签中(请参阅文档http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft,正如@Samuh在他的答案中提到的)。不确定为什么对您不起作用,抱歉。 - rascalking
我们已经在清单文件中编写了这行代码,在纵向模式下键盘可以正常工作。但是在横向模式下,键盘会隐藏输入字段。 - Deeps

5

2

我根据rascalking的回复解决了这个问题。

Dialog dialog = new Dialog(context);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
dialog.setContentView(R.layout.pop_window_service);
WebView webview = (WebView) dialog.findViewById(R.id.pop_webview);
webview.loadUrl(url);

相信我,它是有效的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接