javascript 当软键盘与显示重叠时,如何自动滚动到 Android 中的输入字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24328156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to auto-scroll to input field in Android when the soft keyboard overlaps them on showing?
提问by M. Sfakianos
I am developing a hybrid app using Worklight, and I am experiencing the following issue:
我正在使用 Worklight 开发混合应用程序,但遇到以下问题:
When the user clicks on an input field, the soft keyboard that pops up hides the input field when the latter is relatively low on the screen. The page is scrollable, so the user can scroll and see the field again, but the customer requirements define that the page will auto-scroll until the field is visible.
当用户点击输入栏时,当输入栏在屏幕上相对较低时,弹出的软键盘会隐藏该输入栏。该页面是可滚动的,因此用户可以滚动并再次查看该字段,但客户要求定义该页面将自动滚动直到该字段可见。
Please note that this happens only in the Android environment. In the iPhone and iPad environments the default behavior is the the desired one.
请注意,这仅在 Android 环境中发生。在 iPhone 和 iPad 环境中,默认行为是所需的行为。
Based on my findings, the trick should be done via the android:windowSoftInputMode
attribute in the Android manifest file. However, all my efforts there failed to achieve the auto-scroll.
根据我的发现,这个技巧应该通过android:windowSoftInputMode
Android 清单文件中的属性来完成。但是,我在那里所做的所有努力都未能实现自动滚动。
If there is a solution that is Worklight specific, I would prefer to use it, rather than intervening in the Android native code.
如果有特定于 Worklight 的解决方案,我更愿意使用它,而不是干预 Android 本机代码。
采纳答案by Idan Adar
This isn't really about Worklight at all... but about web apps in general in Android, it seems (from a quick search in Stack Overflow).
这根本不是关于 Worklight 的……而是关于 Android 中的一般网络应用程序,似乎(来自 Stack Overflow 中的快速搜索)。
Here are some suggested solutions, that differ from yours:
以下是一些与您不同的建议解决方案:
- Textbox hidden below keyboard in Android webview
- html textfield in WebView in an Android application is hidden by the soft keyboard
- Keyboard hiding EditText when android:windowTranslucentStatus=true
- You could possibly also use iScroll.js (lite edition) - or implement this yourself by catching the focus event - to scroll a specific amount of pixels upwards.
- Android webview中隐藏在键盘下方的文本框
- Android应用程序中WebView中的html文本框被软键盘隐藏
- 当 android:windowTranslucentStatus=true 时键盘隐藏 EditText
- 您也可以使用 iScroll.js(精简版) - 或者通过捕获焦点事件自己实现 - 向上滚动特定数量的像素。