0

I have created a simple display with a few components including an EditText and a Button. I would like to push up the display when the keyboard appears. I want the button to also be visible when once the keyboard comes up.

Feel free send solution with my edited code below.

I've tried the following in manifest to no success:

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity> 
<activity
   ...
   android:windowSoftInputMode="adjustResize">
</activity> 
<activity
   ...
   android:windowSoftInputMode="adjustNothing">
</activity> 
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

My Code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/windowBackground"
    tools:context=".RegisterFirstNameAndLastNameActivity">

    <RelativeLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/register_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:fontFamily="@font/roboto_medium"
            android:text="SIGN UP"
            android:textColor="@color/white"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/back_arrow_register_first_name_and_last_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:layout_marginLeft="20dp"
            android:padding="20dp"
            app:srcCompat="@drawable/ic_back_arrow" />

        <ImageView
            android:id="@+id/information_icon_register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true"
            android:layout_marginEnd="20dp"
            android:layout_marginRight="20dp"
            app:srcCompat="@drawable/ic_info_outline" />

    </RelativeLayout>


    <View
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="0.5dp"
        android:background="@color/secondaryTextColor"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout3" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:fontFamily="@font/roboto_medium"
        android:text="What is your name?"
        android:textColor="@color/white"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toBottomOf="@+id/view1" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Let your friends find you more easily."
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toBottomOf="@+id/textView6" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/material_design_sign_up_first_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="45dp"
        android:textColorHint="#B9B8B8"
        app:endIconMode="clear_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toBottomOf="@+id/textView5">

        <EditText
            android:id="@+id/sign_up_first_name"
            android:layout_width="350dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="First Name"
            android:inputType="textPersonName"
            android:textColor="@color/white"
            android:textSize="17sp"
            tools:layout_editor_absoluteX="35dp"
            tools:layout_editor_absoluteY="93dp" />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/material_design_sign_up_last_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:textColorHint="#B9B8B8"
        app:endIconMode="clear_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@+id/guideline3"
        app:layout_constraintTop_toBottomOf="@+id/material_design_sign_up_first_name">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/sign_up_last_name"
            android:layout_width="350dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="156dp"
            android:ems="10"
            android:hint="Last Name"
            android:inputType="textPersonName"
            android:textColor="@color/white"
            android:textSize="17sp"
            app:layout_constraintStart_toStartOf="@+id/guideline3"
            app:layout_constraintTop_toBottomOf="@+id/sign_in_email" />

    </com.google.android.material.textfield.TextInputLayout>

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_end="376dp" />

    <Button
        android:id="@+id/continue_first_name_and_last_name_button"
        android:layout_width="350dp"
        android:layout_height="55dp"
        android:layout_marginTop="26dp"
        android:background="@drawable/button_unactive"
        android:enabled="false"
        android:fontFamily="@font/roboto_medium"
        android:text="Continue"
        android:textAllCaps="false"
        android:textColor="@color/windowBackground"
        android:textSize="16sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/material_design_sign_up_last_name" />

</androidx.constraintlayout.widget.ConstraintLayout>
Joe
  • 263
  • 5
  • 20
  • https://stackoverflow.com/questions/61095575/how-to-prevent-one-activity-from-resizing-when-keyboard-opens/61095703#61095703 – MMG Apr 22 '20 at 03:12
  • I dont want to use scrollview here – Joe Apr 22 '20 at 03:35
  • I think my code is what you want, try that – MMG Apr 22 '20 at 03:37
  • I just tried to implement this in my own code, but it didn't really work :(. Could you post an edit of my code maybe i'm doing something wrong? – Joe Apr 22 '20 at 03:46
  • Did you use getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); in oncreate? – MMG Apr 22 '20 at 04:18
  • https://stackoverflow.com/questions/1964789/move-layouts-up-when-soft-keyboard-is-shown – MMG Apr 22 '20 at 04:18
  • Great! It works, however... only the EditText is pushed up, the button is still not being pushed up – Joe Apr 22 '20 at 16:52

0 Answers0