【问题标题】:Soft Keboard covers up TextInputEditText inside a fragment activity软键盘覆盖片段活动中的 TextInputEditText
【发布时间】:2019-10-23 21:19:51
【问题描述】:

我有一个带有 2 个 TextInputEditText 的片段。当我的活动开始时,软键盘会覆盖我的部分输入,当单击键盘上的 NEXT 时,焦点会传递到完全被键盘覆盖的第二个输入。只有当我关闭键盘时才能看到输入的内容。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/back_gradient"
android:orientation="vertical"
android:padding="@dimen/DP10"
tools:context=".activities.MainActivity">

<TextView
    android:id="@+id/tv_new_course_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="@dimen/SP22"
    android:layout_marginBottom="150dp"
    android:text="@string/newCourse"
    android:textColor="@color/colorPrimary"
    android:textSize="@dimen/SP26"
    android:textStyle="bold"/>


<com.google.android.material.textfield.TextInputLayout
    style="@style/LoginTextInputLayoutStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/DP20"
    android:layout_marginRight="@dimen/DP20"
    android:hint="@string/courseName">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_new_course_name"
        style="@style/LoginTextInputEditStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:nextFocusDown="@+id/et_new_course_acronym"
        />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    style="@style/LoginTextInputLayoutStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/DP20"
    android:layout_marginRight="@dimen/DP20"
    android:hint="@string/acronym">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_new_course_acronym"
        style="@style/LoginTextInputEditStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
    android:id="@+id/btn_save_course"
    style="@style/Widget.MaterialComponents.Button.OutlinedButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="@dimen/DP40"
    android:layout_marginBottom="@dimen/DP10"
    android:text="@string/save"
    android:textColor="@color/color_ok"
    app:cornerRadius="@dimen/DP15"
    app:strokeColor="@color/color_ok"
    app:strokeWidth="@dimen/DP2" />

如果在一个活动上膨胀,相同的布局可以正常工作,但这里它是一个片段。

【问题讨论】:

标签: android android-fragments


【解决方案1】:

有多种方法可以解决问题:

流程 1

使用ScrollView 作为根布局并将所有其他布局放入其中。

流程 2 (推荐)

在清单文件中使用 android:windowSoftInputMode="adjustPan|adjustResize"。 有关此的更多详细信息是here.

【讨论】:

    【解决方案2】:

    请将此添加到清单中的活动属性中

    <activity android:name="Your_Activity" android:windowSoftInputMode="adjustPan" ></activity>
    

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多