[英]Adjusting EditTexts when keyboard pops up
I am making a contact book application. 我正在申请通讯录。
Update Contact
activity is responsible for updating existing contacts' details. Update Contact
活动负责更新现有联系人的详细信息。
Following image is the interface of update contact
activity 下图是
update contact
活动的界面
when i clicked on any text field, android device keyboard overlapped the text fields. 当我单击任何文本字段时,Android设备键盘与文本字段重叠。 So to fix that issue, i added following line of code to
update activity
in manifest file 因此,为解决该问题,我添加了以下代码行以
update activity
清单文件中的update activity
android:windowSoftInputMode="adjustPan"
After adding the above line i got the following interface when name field was clicked on 添加以上行后,当单击名称字段时,我得到以下界面
Currently , phone field is displayed over the keyboard only when it is clicked on or when i move the cursor from name field to phone field. 当前,仅在单击时或当我将光标从名称字段移动到电话字段时,电话字段才会显示在键盘上。
I want the phone field to be above the keyboard as well even when name field is clicked on. 我希望电话字段也位于键盘上方,即使单击名称字段也是如此。 How can i achieve this ?
我怎样才能做到这一点?
Following image is what i want when name field is clicked on 下图是单击名称字段时我想要的
What about setting RESIZE instead of PAN? 如何设置RESIZE而不是PAN? You will be able to keep your EditText above the SoftKeyboard.
您将能够将您的EditText保留在SoftKeyboard上方。 Try as follows:
尝试如下:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
However, instead of doing this at runtime, you can set it in the manifest as an Activity (parent) attribute. 但是,可以在清单中将其设置为Activity(父级)属性,而不是在运行时执行此操作。 This will also be handled in your fragment (child):
这也将在您的片段(子片段)中处理:
<activity
android:name=".NameActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
Then, as you can see, the EditText
is above the SoftKeyboard, but from your layout, you have a TextView
with android:layout_alignParentBottom="true"
attribute which will overlap the EditText
: 然后,如您所见,
EditText
在SoftKeyboard的上方,但是从您的布局来看,您有一个TextView
具有android:layout_alignParentBottom="true"
属性,该属性将与EditText
重叠:
To prevent this behaviour, just set the ScrollView above the last TextView as follows: And The XML is Like, 为防止这种行为,只需将ScrollView设置在最后一个TextView上方,如下所示:XML为Like,
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:id="@+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="1">
---
---
---
</ScrollView>
</LinearLayout>
And you will get the following result: 您将得到以下结果:
Put your two fields in LinearLayout
. 将您的两个字段放在
LinearLayout
。 Like the following.. 如下所示
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="bottom"
android:id="@+id/ll">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="name"
android:id="@+id/edit1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="password"
android:id="@+id/edit2"/>
</LinearLayout>
Write this tag in Manifest.xml
inside the activity. 在活动内部的
Manifest.xml
写入此标签。
android:windowSoftInputMode="adjustResize"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.