Android 软键盘覆盖 EditText 字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3295672/
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
Android soft keyboard covers EditText field
提问by Alexis
Is there a way to make the screen scroll to allow the text field to be seen?
有没有办法让屏幕滚动以允许看到文本字段?
回答by Cheryl Simon
Are you asking how to control what is visible when the soft keyboard opens? You might want to play with the windowSoftInputMode. See developer docsfor more discussion.
您是在问如何控制软键盘打开时可见的内容吗?您可能想使用windowSoftInputMode。有关更多讨论,请参阅开发人员文档。
回答by Kuldeep Sakhiya
I had same issues. Try following code:
我有同样的问题。尝试以下代码:
android:windowSoftInputMode="adjustPan"
add it to your manifest.xml in the activity tag of the activity that holds the input. example:
将其添加到包含输入的活动的活动标签中的 manifest.xml。例子:
<activity
android:name=".Activities.InputsActivity"
...
android:windowSoftInputMode="adjustPan"
/>
回答by DanKodi
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.
我遇到了同样的问题,其中软键盘位于位于屏幕底部的 EditText 视图的顶部。我能够通过向我的 AndroidManifest.xml 文件的相关活动添加一行来找到解决方案。
android:windowSoftInputMode="adjustResize|stateHidden"
This is how the whole activity tag looks like:
这是整个活动标签的样子:
<activity
android:name="com.my.MainActivity"
android:screenOrientation="portrait"
android:label="@string/title_activity_main"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
Here the most important value is the adjustResize. This will shift the whole UI up to give room for the softkeyboard.
这里最重要的值是adjustResize。这会将整个 UI 向上移动,为软键盘留出空间。
回答by zmilojko
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.
为什么不尝试添加一个 ScrollView 来包装您想要滚动的任何内容。这是我的做法,我实际上在顶部留下了一个不滚动的标题,而对话框小部件(特别是 EditTexts)在您打开软键盘时会滚动。
<LinearLayout android:id="@+id/HeaderLayout" >
<!-- Here add a header or whatever will not be scrolled. -->
</LinearLayout>
<ScrollView android:id="@+id/MainForm" >
<!-- Here add your edittexts or whatever will scroll. -->
</ScrollView>
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.
我通常会在 ScrollView 中有一个 LinearLayout,但这取决于您。此外,至少在我的设备上,将 Scrollbar 样式设置为 externalInset 有帮助。
回答by Ekundayo Blessing Funminiyi
All you need to do is
你需要做的就是
android:isScrollContainer="true"
source: http://www.davidwparker.com/2011/08/25/android-fixing-window-resize-and-scrolling/
来源:http: //www.davidwparker.com/2011/08/25/android-fixing-window-resize-and-scrolling/
回答by William Moffitt
Sorry for reviving an old thread but no one mentioned setting android:imeOptions="flagNoFullscreen"
in your EditText element
很抱歉恢复了旧线程,但没有人提到android:imeOptions="flagNoFullscreen"
您的 EditText 元素中的设置
回答by Kris Roofe
android:windowSoftInputMode="adjustPan"
android:isScrollContainer="true"
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"
适用于 android EditText,而不适用于 webview 或 xwalkview。当软键盘隐藏您使用的 webview 或 xwalkview 中的输入时android:windowSoftInputMode="adjustResize"
回答by Luis Miguel Serrano
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.
我相信您可以使用轨迹球使其滚动,这可能最终通过选择方法以编程方式实现,但这只是一个想法。我知道轨迹球方法通常有效,但至于执行此操作并通过代码使其工作的确切方法,我不确定。
希望有帮助。
回答by umesh shakya
add this single line to your relative activity where key board cover edit text.inside onCreat()method of activity.
将此单行添加到您的相关活动中,其中键盘盖编辑 text.inside onCreat() 活动方法。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
回答by Beast77
I 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
我知道这很旧,但上述解决方案都不适合我。经过大量调试,我发现了这个问题。解决方案是android:windowTranslucentStatus
在我的styles.xml中将属性设置为false