0

I have a fragment with 2 TextInputEditText. When my activity starts, the soft keyboard covers part of my input, and when clicking NEXT on the keyboard the focus passes to the second input that is completely covered by the keyboard. It´s possible to see what has been typed only when I close the keyboard.

enter image description here

This is my layout:

<?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" />

The same layout works fine if inflated on an activity, but here it´s a fragment.

Ricardo Martin
  • 129
  • 1
  • 8
  • Possible duplicate of [Keyboard overlapping EditText on click](https://stackoverflow.com/questions/33109976/keyboard-overlapping-edittext-on-click) – Santanu Sur Jun 08 '19 at 21:23

2 Answers2

2

There are multiple ways to remove the problem:

Process 1

Use a ScrollView as the root layout and put all the other layouts inside it.

Process 2 (recommended)

Use android:windowSoftInputMode="adjustPan|adjustResize" in your manifest file. More detail about this is here.

Sayok Majumder
  • 1,012
  • 13
  • 28
1

please add this in your activity attribute in the manifest

<activity android:name="Your_Activity" android:windowSoftInputMode="adjustPan" ></activity>
ismail alaoui
  • 5,748
  • 2
  • 21
  • 38