软键盘覆盖EditText(adjustPan和AdjustResize无效)

时间:2018-07-23 18:17:10

标签: android android-edittext android-softkeyboard adjustpan

我有一个布局,其中多个EditTextScrollView包裹。我已经在滚动视图中将fitsSystemWindows设置为true,如下所示,

android:fitsSystemWindows="true"

在android manifest中,我尝试添加

android:windowSoftInputMode="adjustResize"

android:windowSoftInputMode="adjustPan"

但是这些都不起作用,我的EditText仍然被softkeyboard所覆盖。

我已添加文件以供进一步参考。

activity.xml

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/login_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_theme"
        android:fitsSystemWindows="true"
        tools:context=".SignUpActivity"
        android:scrollbars="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="40dp"
            android:paddingTop="40dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                    android:layout_marginRight="@dimen/activity_horizontal_double_margin"
                    android:background="@drawable/background_card_login"
                    android:gravity="center_horizontal"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/activity_horizontal_double_margin"
                        android:gravity="center_horizontal"
                        android:text="Sign Up"
                        android:textColor="@color/textColorDark"
                        android:textSize="@dimen/text_size_xxlarge"
                        android:textStyle="bold" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_double_margin"
                        android:text="First Name*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <EditText
                        android:id="@+id/et_first_mame"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:background="@drawable/background_edittext_login"
                        android:imeOptions="actionNext"
                        android:inputType="text"
                        android:maxLines="1"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin" />

                    <TextView
                        android:id="@+id/tv_first_name_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_margin"
                        android:text="Last Name*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <EditText
                        android:id="@+id/et_last_mame"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:background="@drawable/background_edittext_login"
                        android:imeOptions="actionNext"
                        android:inputType="text"
                        android:maxLines="1"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin" />

                    <TextView
                        android:id="@+id/tv_last_name_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_margin"
                        android:text="Email ID*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <EditText
                        android:id="@+id/et_email_address"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:background="@drawable/background_edittext_login"
                        android:imeOptions="actionNext"
                        android:inputType="textEmailAddress"
                        android:maxLines="1"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin" />

                    <TextView
                        android:id="@+id/tv_email_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_margin"
                        android:text="Password*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <EditText
                        android:id="@+id/et_password"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:background="@drawable/background_edittext_login"
                        android:imeOptions="actionNext"
                        android:inputType="textPassword"
                        android:maxLines="1"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin" />

                    <TextView
                        android:id="@+id/tv_password_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_margin"
                        android:text="Confirm Password*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <EditText
                        android:id="@+id/et_password_confirm"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:background="@drawable/background_edittext_login"
                        android:imeOptions="actionNext"
                        android:inputType="textPassword"
                        android:maxLines="1"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin" />

                    <TextView
                        android:id="@+id/tv_password_confirm_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/activity_horizontal_double_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_margin"
                        android:text="Mobile*"
                        android:textColor="@color/textColorLighter"
                        android:textSize="@dimen/text_size_large" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:orientation="horizontal">

                        <LinearLayout
                            android:id="@+id/ll_country_code_container"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal">

                            <ImageView
                                android:id="@+id/iv_country_flag"
                                android:layout_width="40dp"
                                android:layout_height="25dp"
                                android:layout_gravity="center_vertical"
                                android:background="@drawable/usa"/>

                            <TextView
                                android:id="@+id/et_country_code"
                                android:layout_width="80dp"
                                android:layout_height="40dp"
                                android:layout_gravity="center_vertical"
                                android:layout_marginLeft="@dimen/activity_horizontal_half_margin"
                                android:layout_weight="2"
                                android:background="@drawable/background_edittext_login"
                                android:gravity="center"
                                android:text="+1"
                                android:maxLength="5"
                                android:maxLines="1"
                                android:paddingLeft="@dimen/activity_horizontal_margin" />

                        </LinearLayout>


                        <EditText
                            android:id="@+id/et_phone_number"
                            android:layout_width="0dp"
                            android:layout_height="40dp"
                            android:layout_marginLeft="@dimen/activity_horizontal_half_margin"
                            android:layout_weight="4"
                            android:background="@drawable/background_edittext_login"
                            android:digits="0123456789"
                            android:inputType="phone"
                            android:lines="1"
                            android:maxLines="1"
                            android:paddingLeft="@dimen/activity_horizontal_margin"
                            android:paddingRight="@dimen/activity_horizontal_margin" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/tv_phone_number_error"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:textSize="12sp"
                        android:textColor="@color/textColorError"/>

                    <Button
                        android:id="@+id/action_sign_up"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/login_button_height"
                        android:layout_marginBottom="@dimen/activity_vertical_half_margin"
                        android:layout_marginLeft="@dimen/activity_horizontal_margin"
                        android:layout_marginRight="@dimen/activity_horizontal_margin"
                        android:layout_marginTop="@dimen/activity_horizontal_double_margin"
                        android:background="@drawable/background_button_quiz"
                        android:text="Sign Up"
                        android:textAllCaps="false"
                        android:textColor="@color/textColorWhite"
                        android:textSize="@dimen/text_size_mlarge" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/activity_horizontal_half_margin"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/already_have_an_account" />

                        <TextView
                            android:id="@+id/tv_sign_in"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/activity_horizontal_quart_margin"
                            android:text="@string/sign_in"
                            android:textStyle="bold" />
                    </LinearLayout>

                </LinearLayout>
            </RelativeLayout>

        </RelativeLayout>

    </ScrollView>

AndroidManifest.xml

    <activity
        android:name=".SignUpActivity"
        android:windowSoftInputMode="adjustPan"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

styles.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

background_edittext_login.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/login_edit_text_background" />
    <corners android:radius="@dimen/login_edit_text_radius"/>
    <stroke android:color="@color/login_edit_text_background"
        android:width="@dimen/login_edit_text_radius"/>
</shape>

谢谢!

0 个答案:

没有答案