Android 键盘隐藏 EditText
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24262414/
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 Keyboard hides EditText
提问by Robin Royal
When I try to write something in an EditText which is at the bottom of the screen, the soft keyboard hides the EditText. How can I resolve this issue? Below is my xml code. I'm using this in a Fragment.
当我尝试在屏幕底部的 EditText 中写一些东西时,软键盘隐藏了 EditText。我该如何解决这个问题?下面是我的 xml 代码。我在片段中使用它。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayoutTopDetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayoutTop"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_design1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="100"
android:orientation="horizontal" >
<ImageView
android:id="@+id/ImageViewProfImagePostDetail"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginTop="2dp"
android:layout_weight="24.84"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewNamePostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Robin"
android:textSize="17sp" />
<TextView
android:id="@+id/textViewLocationPostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:drawableLeft="@drawable/location"
android:text="beijing, China" />
<TextView
android:id="@+id/textViewTimeAgoPostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 18min ago" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="15"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewReportAbusePostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/flag"
android:paddingLeft="5dp" />
<TextView
android:id="@+id/textViewDeletePostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:background="@drawable/delete"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/textViewDescriptionPostDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:singleLine="false"
android:text="Description or caption of the post"
android:textSize="17sp" />
</LinearLayout>
<ImageView
android:id="@+id/feedPostedImagePostDetail"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginTop="5dp"
android:scaleType="fitCenter"
android:visibility="gone" />
<LinearLayout
android:id="@+id/linearLayoutOptions"
android:layout_width="fill_parent"
android:layout_height="33dp"
android:layout_marginTop="2dp"
android:layout_weight="100"
android:background="@drawable/bar"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewShakePostDetail"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_weight="25"
android:drawableLeft="@drawable/like"
android:gravity="center"
android:singleLine="true"
android:text="Shake"
android:textSize="12sp" />
<TextView
android:id="@+id/textViewCommentPostDetail"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="41"
android:drawableLeft="@drawable/comment"
android:gravity="center"
android:paddingLeft="20dp"
android:text="Comment" />
<TextView
android:id="@+id/textViewSharePostDetail"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="33"
android:drawableLeft="@drawable/share"
android:gravity="center"
android:paddingLeft="20dp"
android:text="Spread" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/listViewFeedsDetail1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayoutTopDetails"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp" >
</ListView>
<LinearLayout
android:id="@+id/linearLayoutPostcomment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/listViewFeedsDetail1"
android:background="#FFFFFF"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="@+id/editTextComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="80" />
<Button
android:id="@+id/buttonPostComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:background="#F0F8FF"
android:text="Post" >
</Button>
</LinearLayout>
</RelativeLayout>
</ScrollView>
I have tried to resolve this issue by adding changes through code but no success.
我曾尝试通过代码添加更改来解决此问题,但没有成功。
Below is the image before and after clicking on the EditText.
下面是单击 EditText 之前和之后的图像。
回答by Kishan Dhamat
In your manifest put this in your perticular activity:
在您的清单中,将其放入您的特定活动中:
android:windowSoftInputMode="adjustPan"
回答by Robin Royal
For that you have to declared in your activity manifeast
为此,您必须在活动清单中声明
<activity
android:name=".activityname"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
回答by Rahul Raina
Here is simple solutionfor Android EditText issue of hiding behind SoftKeypad. Use the code in AndroidManifest.xml file of the project module.
下面是简单的解决方案的背后隐藏SoftKeypad Android的EditText上的问题。使用项目模块的 AndroidManifest.xml 文件中的代码。
<activity
android:name="com.example.MainActivity"
android:label="@string/activity_main"
android:windowSoftInputMode="adjustResize|stateHidden" />
This code worked for me.
Inside the manifest file in activity tag add this attribute:
这段代码对我有用。
在活动标记的清单文件中添加此属性:
android:windowSoftInputMode="adjustResize|stateHidden"
There are more such values for this attribute (android:windowSoftInputMode
) which will come as recommendation list. You can check with them also.
此属性 ( android:windowSoftInputMode
)有更多这样的值,它们将作为推荐列表出现。你也可以和他们核对一下。
回答by Kishor N R
Declare windowSoftInputMode="adjustResize" in manifest.xml file
在 manifest.xml 文件中声明 windowSoftInputMode="adjustResize"
<activity
android:name=".example"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
provide scroll view to the xml layout file
为 xml 布局文件提供滚动视图
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:isScrollContainer="false">
// add edittext here...
</ScrollView>
</RelativeLayout>
回答by Ramakishna Balla
Use the below code where:
在以下位置使用以下代码:
InputMethodManager ipmm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
ipmm.hideSoftInputFromWindow(url.getWindowToken(), 0);
where url in my code is:
我的代码中的 url 是:
url = (EditText) findViewById(R.id.eT_webbrowser);
or Try this:
或试试这个:
InputMethodManager ipmm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
ipmm.hideSoftInputFromWindow(null, 0);
As another option try this: This always hides the soft input mode such that your EditText is visible
作为另一种选择,试试这个:这总是隐藏软输入模式,以便您的 EditText 可见
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
回答by Hichem Laroussi
The solution for me was, simply, adding this to the parent layout : android:fitsSystemWindows="true"
对我来说,解决方案很简单,将其添加到父布局中:android:fitsSystemWindows="true"
回答by Kirill Smirnov
I handled that by adding ScrollView around View with EditText inside.
我通过在 View 周围添加 ScrollView 来处理这个问题,其中 EditText 里面。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
// Other views
<EditText ... />
</ScrollView>
Adding tags to Android Manifest didn't help me.
向 Android Manifest 添加标签对我没有帮助。