Android 软键盘覆盖 EditText 字段
有没有办法让屏幕滚动以允许看到文本字段?
Is there a way to make the screen scroll to allow the text field to be seen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有办法让屏幕滚动以允许看到文本字段?
Is there a way to make the screen scroll to allow the text field to be seen?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(16)
我有同样的问题。尝试以下代码:
将其添加到保存输入的活动的活动标记中的manifest.xml中。例子:
I had same issues. Try following code:
add it to your manifest.xml in the activity tag of the activity that holds the input. example:
您是想问如何控制软键盘打开时可见的内容吗?您可能想使用 windowSoftInputMode。有关详细讨论,请参阅开发者文档。
Are you asking how to control what is visible when the soft keyboard opens? You might want to play with the windowSoftInputMode. See developer docs for more discussion.
我遇到了同样的问题,软键盘位于位于屏幕底部的 EditText 视图的顶部。我能够通过向 AndroidManifest.xml 文件的相关活动添加一行来找到解决方案。
整个活动标签如下所示:
这里最重要的值是 adjustmentResize。这会将整个 UI 向上移动,为软键盘腾出空间。
I had the same issue where the softkeyboard was on top of the EditText views which were placed on the bottom of the screen. I was able to find a solution by adding a single line to my AndroidManifest.xml file's relevant activity.
This is how the whole activity tag looks like:
Here the most important value is the adjustResize. This will shift the whole UI up to give room for the softkeyboard.
为什么不尝试添加一个 ScrollView 来包装您想要滚动的任何内容。这是我的做法,我实际上在顶部留下了一个不滚动的标题,而当您打开软键盘时对话框小部件(特别是 EditTexts)会滚动。
我通常会在 ScrollView 中使用 LinearLayout,但这取决于你。另外,将滚动条样式设置为 OutsideInset 会有所帮助,至少在我的设备上是这样。
Why not try to add a ScrollView to wrap whatever it is you want to scroll. Here is how I have done it, where I actually leave a header on top which does not scroll, while the dialog widgets (in particular the EditTexts) scroll when you open soft keypad.
I would typically have a LinearLayout inside the ScrollView, but that is up to you. Also, setting Scrollbar style to outsideInset helps, at least on my devices.
您需要做的就是
来源: http: //www.davidwparker.com/2011/08/25/android-fixing-window-resize-and-scrolling/
All you need to do is
source: http://www.davidwparker.com/2011/08/25/android-fixing-window-resize-and-scrolling/
很抱歉恢复旧线程,但没有人提到在您的 EditText 元素中设置
android:imeOptions="flagNoFullscreen"
Sorry for reviving an old thread but no one mentioned setting
android:imeOptions="flagNoFullscreen"
in your EditText element适用于 android EditText,但不适用于 webview 或 xwalkview。当软键盘隐藏 webview 或 xwalkview 中的输入时,您必须使用
android:windowSoftInputMode="adjustResize"
works for android EditText, while it not works for webview or xwalkview. When soft keyboard hide the input in webview or xwalkview you have use
android:windowSoftInputMode="adjustResize"
我相信您可以使用轨迹球使其滚动,这最终可能通过选择方法以编程方式实现,但这只是一个想法。我知道轨迹球方法通常有效,但至于执行此操作并使其通过代码工作的确切方法,我不确定。
希望有帮助。
I believe that you can make it scroll by using the trackball, which might be achieved programmatically through selection methods eventually, but it's just an idea. I know that the trackball method typically works, but as for the exact way to do this and make it work from code, I do not sure.
Hope that helps.
将这一行添加到您的相关活动中,其中键盘覆盖编辑文本。活动的 onCreat() 方法内。
add this single line to your relative activity where key board cover edit text.inside onCreat()method of activity.
只需添加
android:gravity="bottom" android:paddingBottom="10dp"
根据您的编辑文本大小更改 paddingBottom
just add
android:gravity="bottom" android:paddingBottom="10dp"
change paddingBottom according to your size of edittext
我的解决方案是将布局放在 ScrollView 中,如果内容超过屏幕高度,用户可以滚动查看整个内容,并且内容的 EditText 将完全可见。如果它位于内容的末尾,则需要为要显示的视图添加足够的底部边距。
My solution is to put the layout in a ScrollView, If the content is over a screen height, user can scroll to see the whole content and the EditText of the content will fully be seen. If it is at the end of the content, to add enough margin bottom for the view to be shown is necessary.
我知道这已经过时了,但上述解决方案都不适合我。经过大量调试后,我发现了这个问题。
解决方案是在 styles.xml 中将
android:windowTranslucentStatus
属性设置为 falseI know this is old but none of the above solutions worked for me. After extensive debugging, I figured out the issue.
The solution is setting the
android:windowTranslucentStatus
attribute to false in my styles.xml如果 EditText 字段被键盘覆盖,请使用以下代码:
如果您希望光标位于聚焦的 EditText 中,则在
之后使用
这有助于在聚焦的 EditText 中获取焦点和光标。EditText.requestFocus()
>EditText?.getParent()?.requestChildFocus(EditText,EditText)If EditText Field is been covered by the KeyBoard Use the following code:
If you want the Cursor to be in the Focused EditText than use
EditText.requestFocus()
after theEditText?.getParent()?.requestChildFocus(EditText,EditText)
which helps to get the focus and Cursor in the Focused EditText.上述解决方案工作完美,但如果您使用全屏活动(半透明状态栏),那么这些解决方案可能不起作用。
因此,要全屏显示,请在 Activity 的 onCreate 函数中使用此代码。
例子:
The above solution work perfectly but if you are using Fullscreen activity(translucent status bar) then these solutions might not work.
so for fullscreen use this code inside your onCreate function on your Activity.
Example:
编辑 AndroidManifest.xml
将其添加到布局文件的根视图中。
就这样。
Edit your AndroidManifest.xml
Add this to your root view of Layout file.
That's all.
我遇到了同样的问题,并搜索了说要添加
adjustmentPan 的人,而在我的情况下,
adjustmentResize 有效。
I had the same issue and searching the people said to add
adjustPan
, while in my caseadjustResize
worked.