I’m making an android app by kotlin. I want when the keyboard show, the screen auto move up and the element not being hided by the keyboard. My layout only contain FrameLayout and ConstrainLayout. I tried adding android:windowSoftInputMode=”adjustResize” in AndroidManifest and programmatically but it not work.
This is my Fragment code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
tools:context=".SignInFragment"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_color"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bg_intro"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_intro_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:src="@drawable/intro_pic"
android:scaleType="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.3"/>
<ImageView
android:id="@+id/iv_intro_image2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="@drawable/gradient_background"
app:layout_constraintBottom_toBottomOf="@id/iv_intro_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_intro_image2"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
>
<TextView
android:id="@+id/tv_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log In"
android:textSize="30sp"
android:textColor="@color/orange"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/et_username_or_email"
android:layout_width="match_parent"
android:layout_height="70dp"
android:autofillHints=""
android:hint="username or email"
android:ems="8"
android:background="@drawable/edittext_bg"
android:textColorHint="@color/white"
android:textColor="@color/white"
android:inputType="text"
android:layout_marginTop="40dp"
android:padding="20dp"
app:layout_constraintTop_toBottomOf="@id/tv_login"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="70dp"
android:hint="password"
android:ems="8"
android:background="@drawable/edittext_bg"
android:textColorHint="@color/white"
android:textColor="@color/white"
android:inputType="textPassword"
android:layout_marginTop="20dp"
android:padding="20dp"
app:layout_constraintTop_toBottomOf="@id/et_username_or_email"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_forgot_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="@id/password">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password?"
android:textColor="@color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't have an account?"
android:textColor="@color/white"
android:layout_gravity="end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:text="Log In"
android:background="@drawable/button_bg"
app:layout_constraintTop_toBottomOf="@id/layout_forgot_password"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Fragment is implement in activity:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".AuthenticationActivity">
<FrameLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.app.SignInFragment"
tools:layout="@layout/fragment_sign_in" />
</FrameLayout>
</layout>
this is result:
enter image description here