Клавиатура исчезает в фрагменте при прокрутке вверх - PullRequest
0 голосов
/ 22 февраля 2020

В моем фрагменте есть Edittext, который принимает числа в качестве ввода, моя проблема в том, что когда я прокручиваю экран, моя клавиатура исчезает, но я не хочу, чтобы она исчезала до тех пор, пока пользователь не нажмет клавишу назад на панели навигации. , Мой родитель - Nestedscrollview, а дочерний - макет ограничения.

Пробовал

android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
android:windowSoftInputMode="adjustResize|stateVisible"

, но ничего не получалось, даже я пытался принудительно показать клавиатуру в onScrollListener, но это не помогло мне. Как это сделать?

Мой XML:

 <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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"
android:fillViewport="true"
android:scrollbars="none">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    android:focusableInTouchMode="true">


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.03" />


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.97" />

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/select_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/dimen_15dp"
        android:clickable="true"
        android:clipChildren="false"
        android:focusable="true"
        android:foreground="@drawable/ripple"
        android:paddingTop="@dimen/dimen_5dp"
        android:paddingEnd="@dimen/dimen_5dp"
        android:paddingBottom="@dimen/dimen_5dp"
        android:src="@drawable/left_arrow"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.00"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.00" />

    <androidx.appcompat.widget.AppCompatTextView

        android:id="@+id/back_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="8dp"
        android:layout_marginTop="15dp"
        android:clickable="true"
        android:focusable="true"
        android:fontFamily="@font/opensans_bold"
        android:paddingTop="@dimen/dimen_5dp"
        android:paddingEnd="@dimen/dimen_5dp"
        android:paddingBottom="@dimen/dimen_5dp"
        android:text="@string/otp"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@+id/select_back"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.00" />


    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/feedback"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="15dp"
        android:clickable="true"
        android:focusable="true"
        android:fontFamily="@font/roboto_regular"
        android:foreground="?android:selectableItemBackground"
        android:paddingStart="@dimen/dimen_5dp"
        android:paddingTop="@dimen/dimen_5dp"
        android:paddingBottom="@dimen/dimen_5dp"
        android:text="@string/feedback_text"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toEndOf="@+id/back_title"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.00" />

    <View
        android:id="@+id/line"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginTop="@dimen/dp_12"
        android:background="@color/grey_text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/select_back"
        app:layout_constraintVertical_bias="0.0" />


    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_otp_icon"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/line"
        app:layout_constraintVertical_bias="0.05" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/your_otp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/opensans_bold"
        android:text="@string/enter_otp_heading"
        android:textColor="@color/black"
        android:textSize="@dimen/dimen_20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/image"
        app:layout_constraintVertical_bias="0.062" />


    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/mobile_no"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dimen_40dp"
        android:fontFamily="@font/roboto_regular"
        android:text="@string/opt_sendto"
        android:textColor="@color/bottom_title"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/your_otp"
        app:layout_constraintVertical_bias="0.02" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/change_mobile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/dimen_10dp"
        android:clickable="true"
        android:focusable="true"
        android:fontFamily="@font/opensans_bold"
        android:foreground="?android:selectableItemBackground"
        android:text="@string/change_no"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/mobile_no"
        app:layout_constraintVertical_bias="0.01" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/otpNumberInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dimen_50dp"
        android:theme="@style/KSTextInputLayout"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/change_mobile"
        app:layout_constraintVertical_bias="0">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/otpNumberInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/edit_text_normal"
            android:backgroundTint="@color/edittext_grey"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:fontFamily="@font/roboto_regular"
            android:hint="@string/enter_otp"
            android:imeOptions="actionDone"
            android:inputType="numberPassword"
            android:maxLength="4"
            android:padding="@dimen/dp_12"
            android:paddingStart="@dimen/dimen_5dp"
            android:paddingTop="@dimen/dimen_5dp"
            android:paddingEnd="@dimen/dimen_5dp"
            android:paddingBottom="@dimen/dimen_5dp"
            android:textColor="@color/textview_black"
            android:textColorHint="@color/textview_black"
            android:textCursorDrawable="@drawable/cursor_color"
            android:textSize="@dimen/dimen_16sp" />

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

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/nextButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dimen_50dp"
        android:layout_marginBottom="@dimen/dimen_20dp"
        android:background="@drawable/button_background"
        android:clickable="true"
        android:focusable="true"
        android:fontFamily="@font/roboto_regular"
        android:foreground="?attr/selectableItemBackground"
        android:padding="@dimen/dimen_10dp"
        android:text="@string/Continue"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/otpNumberInputLayout"
        app:layout_constraintVertical_bias="0">

        <requestFocus />
    </androidx.appcompat.widget.AppCompatButton>


    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/timer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/dimen_40dp"
        android:fontFamily="@font/opensans_bold"
        android:text="0:00"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="@dimen/dimen_16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/nextButton"
        app:layout_constraintVertical_bias="0" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/no_otp"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dimen_30dp"
        android:layout_marginBottom="@dimen/dimen_30dp"
        android:fontFamily="@font/roboto_regular"
        android:gravity="center"
        android:text="@string/not_received_otp_text"
        android:textColor="@color/bottom_title"
        android:textSize="@dimen/dimen_14sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@id/guideline2"
        app:layout_constraintStart_toStartOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@+id/timer"
        app:layout_constraintVertical_bias="0" />


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
...