1

尝试EditText输入EditText.

如何防止软键盘覆盖我的EditText字段?

按下后退按钮后,我可以看到我输入的内容,因为软键盘不再覆盖EditText.

我正在使用 Galaxy 10.1 英寸平板电脑。

XML

<ScrollView
            android:layout_width="wrap_content"
            android:layout_height="400dp" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="1) Project"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:id="@+id/projectET"
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:textSize="25sp"
                        android:ems="10"
                        android:hint="Project" 
                        android:inputType="textCapWords"
                        android:layout_gravity="bottom"/>

                    <CheckBox
                        android:id="@+id/projectCBM"
                        android:layout_width="wrap_content"
                        android:layout_height="55dp" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="2) Customer"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:id="@+id/customerET"
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:inputType="textCapWords"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:hint="Customer" />

                    <CheckBox
                        android:id="@+id/customerCBM"
                        android:layout_width="wrap_content"
                        android:layout_height="55dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/material1"
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="3) Material"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:id="@+id/materialET"
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:textSize="25sp"
                        android:layout_gravity="bottom"
                        android:inputType="textCapWords"
                        android:ems="10"
                        android:hint="Material" />

                    <CheckBox
                        android:id="@+id/materialCBM"
                        android:layout_width="wrap_content"
                        android:layout_height="55dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="4) Phase"
                        android:layout_gravity="bottom"
                        android:textColor="#000000"
                        android:textSize="25sp" />

                    <EditText
                        android:id="@+id/fazeET"
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="Phase" />

                    <CheckBox
                        android:id="@+id/fazeCBM"
                        android:layout_width="wrap_content"
                        android:layout_height="55dp"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="5)"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="wrap_content"
                        android:layout_height="55dp"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="6)"
                        android:layout_gravity="bottom"
                        android:textColor="#000000"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="wrap_content"
                        android:layout_height="55dp"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="7)"
                        android:layout_gravity="bottom"
                        android:textColor="#000000"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="wrap_content"
                        android:layout_height="55dp"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="8)"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="55dp"
                        android:layout_height="wrap_content"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="9)"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="55dp"
                        android:layout_height="wrap_content"
                        android:enabled="false" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:text="10)"
                        android:textColor="#000000"
                        android:layout_gravity="bottom"
                        android:textSize="25sp" />

                    <EditText
                        android:layout_width="500dp"
                        android:layout_height="wrap_content"
                        android:ems="10"
                        android:layout_gravity="bottom"
                        android:textSize="25sp"
                        android:enabled="false"
                        android:hint="" />

                    <CheckBox
                        android:layout_width="55dp"
                        android:layout_height="wrap_content"
                        android:enabled="false" />
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
4

2 回答 2

5

您需要使用windowSoftInputMode。这将允许您的 UI 在键盘出现时调整大小。允许用户EditText在输入键盘时看到。

在您的 AndroidManifest.xml 中将此属性添加到您的Activity.

android:windowSoftInputMode="adjustPan"

参考

于 2012-08-09T14:14:26.860 回答
0

好吧,我认为您的 上方有一些固定布局ScrollView,因为通常ScrollView会自动滚动到 Focused 组件。

所以,如果我是对的,有两种选择(我知道):

  1. ScrollView键盘放在键盘上或
  2. 验证布局更改以动态地将ScrollView其带到上方和可见的位置,在ScrollView可见后它将自动向EditText用户显示权限。
于 2012-08-09T14:17:29.170 回答