Как скрыть кнопку нижнего колонтитула при показе программной клавиатуры? - PullRequest
1 голос
/ 13 января 2020

Я не знаю, как скрыть кнопку нижнего колонтитула при показе софт-клавиатуры. пожалуйста, помогите мне.

[AndroidManifest.xml]

 <activity
                android:name=".presentation.signup.SignUpActivity"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustResize" />

[activity_sign_up.xml]

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layout_sign_up"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/blue_4c_color">

        <!-- toolbar -->
        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar_sign_up"
                style="@style/toolbarCommonStyle"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        <!-- toolbar title -->
        <TextView
                android:id="@+id/tv_toolbar_title_sign_up"
                style="@style/toolbarTitleCommonStyle"
                android:text="@string/sign_up"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        <!-- signup fragment -->
        <FrameLayout
                android:id="@+id/fragment_container_sign_up"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@id/view_footer_sign_up"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/toolbar_sign_up" />

        <!-- footer button -->
        <View
                android:id="@+id/view_footer_sign_up"
                style="@style/footerBgViewStyle"
                android:background="@color/footer_view_sign_up_color"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

        <Button
                android:id="@+id/btn_next_sign_up"
                style="@style/footerBtnStyle"
                android:background="@drawable/shape_square_radius_dark_blue"
                android:text="@string/next"
                app:layout_constraintBottom_toBottomOf="@+id/view_footer_sign_up"
                app:layout_constraintEnd_toEndOf="@+id/view_footer_sign_up"
                app:layout_constraintStart_toStartOf="@+id/view_footer_sign_up"
                app:layout_constraintTop_toTopOf="@+id/view_footer_sign_up" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

[frag_sign_up_email_password.xml]

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <ScrollView
            android:id="@+id/scrollview_sign_up_email_password"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layout_sign_up_email_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/blue_4c_color"
                android:focusable="true"
                android:focusableInTouchMode="true">

            <!-- id -->
            <TextView
                    android:id="@+id/tv_title_id_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="19dp"
                    android:layout_marginEnd="16dp"
                    android:text="@string/id"
                    android:textAppearance="@style/Font16RegularStyle"
                    android:textColor="@color/white_color"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/et_id_sign_up"
                    style="@style/editTextCommonStyle"
                    android:layout_width="0dp"
                    android:layout_height="48dp"
                    android:layout_marginTop="9dp"
                    android:hint="@string/hint_input_email"
                    android:inputType="textEmailAddress"
                    app:layout_constraintEnd_toStartOf="@id/btn_double_check_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@+id/tv_title_id_sign_up" />

            <Button
                    android:id="@+id/btn_double_check_sign_up"
                    style="@style/elevationCommonStyle"
                    android:layout_width="84dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:background="@drawable/shape_btn_sign_up"
                    android:text="@string/double_check"
                    android:textAppearance="@style/Font16RegularStyle"
                    android:textColor="@color/white_color"
                    app:layout_constraintBottom_toBottomOf="@id/et_id_sign_up"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@id/et_id_sign_up"
                    app:layout_constraintTop_toTopOf="@id/et_id_sign_up" />

            <TextView
                    android:id="@+id/tv_notify_id_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="9dp"
                    android:text="@string/notify_sign_up_email"
                    android:textAppearance="@style/Font14RegularStyle"
                    android:textColor="@color/white_80_alpha_color"
                    app:layout_constraintEnd_toEndOf="@id/tv_title_id_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@id/et_id_sign_up" />

            <!-- password -->
            <TextView
                    android:id="@+id/tv_title_password_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="25dp"
                    android:text="@string/password"
                    android:textAppearance="@style/Font16RegularStyle"
                    android:textColor="@color/white_color"
                    app:layout_constraintEnd_toEndOf="@id/tv_title_id_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@id/tv_notify_id_sign_up" />

            <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/et_password_sign_up"
                    style="@style/editTextCommonStyle"
                    android:layout_width="0dp"
                    android:layout_height="48dp"
                    android:layout_marginTop="9dp"
                    android:hint="@string/hint_input_password"
                    android:inputType="textPassword"
                    app:layout_constraintEnd_toEndOf="@id/btn_double_check_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_password_sign_up"
                    app:layout_constraintTop_toBottomOf="@+id/tv_title_password_sign_up" />

            <TextView
                    android:id="@+id/tv_notify_password_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="9dp"
                    android:text="@string/notify_sign_up_password"
                    android:textAppearance="@style/Font14RegularStyle"
                    android:textColor="@color/white_80_alpha_color"
                    app:layout_constraintEnd_toEndOf="@id/tv_title_id_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@id/et_password_sign_up" />

            <ImageView
                    android:id="@+id/iv_check_password_sign_up"
                    style="@style/elevationCommonStyle"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginEnd="17dp"
                    android:background="@drawable/selector_sign_up_check"
                    app:layout_constraintBottom_toBottomOf="@id/et_password_sign_up"
                    app:layout_constraintEnd_toEndOf="@id/et_password_sign_up"
                    app:layout_constraintTop_toTopOf="@id/et_password_sign_up" />

            <!-- confirm password again  -->
            <TextView
                    android:id="@+id/tv_title_password_again_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="25dp"
                    android:text="@string/password_again"
                    android:textAppearance="@style/Font16RegularStyle"
                    android:textColor="@color/white_color"
                    app:layout_constraintEnd_toEndOf="@id/tv_title_id_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@id/tv_notify_password_sign_up" />

            <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/et_password_again_sign_up"
                    style="@style/editTextCommonStyle"
                    android:layout_width="0dp"
                    android:layout_height="48dp"
                    android:layout_marginTop="9dp"
                    android:hint="@string/hint_input_password"
                    android:inputType="textPassword"
                    app:layout_constraintEnd_toEndOf="@id/btn_double_check_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_password_sign_up"
                    app:layout_constraintTop_toBottomOf="@+id/tv_title_password_again_sign_up" />

            <TextView
                    android:id="@+id/tv_notify_password_again_sign_up"
                    style="@style/excludedPaddingStyle"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="9dp"
                    android:text="@string/notify_sign_up_password_again"
                    android:textAppearance="@style/Font14RegularStyle"
                    android:textColor="@color/white_80_alpha_color"
                    app:layout_constraintEnd_toEndOf="@id/tv_title_id_sign_up"
                    app:layout_constraintStart_toStartOf="@id/tv_title_id_sign_up"
                    app:layout_constraintTop_toBottomOf="@id/et_password_again_sign_up" />

            <ImageView
                    android:id="@+id/iv_check_password_again_sign_up"
                    style="@style/elevationCommonStyle"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginEnd="17dp"
                    android:background="@drawable/selector_sign_up_check"
                    app:layout_constraintBottom_toBottomOf="@id/et_password_again_sign_up"
                    app:layout_constraintEnd_toEndOf="@id/et_password_again_sign_up"
                    app:layout_constraintTop_toTopOf="@id/et_password_again_sign_up" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
</layout>

Я хочу скрыть кнопку нижнего колонтитула (activity_sign_up. xml), когда editText (frag_sign_up_email_password) имеет фокус.

Я хочу, чтобы нижняя кнопка исчезла в то же время, когда отображается программная клавиатура.

Ответы [ 2 ]

1 голос
/ 13 января 2020

Вы можете использовать onGlobalLayoutListener, чтобы узнать, когда отображается клавиатура.

 view?.viewTreeObserver?.addOnGlobalLayoutListener {
     val rect = Rect()
     view?.getWindowVisibleDisplayFrame(rect)
     val screenHeight = view?.rootView?.height
     val keypadHeight = screenHeight?.minus(rect.bottom) ?: return

     if (keypadHeight > screenHeight * KEYBOARD_MINIMUM_HEIGHT_PERCENTAGE) {
         //keyboard is shown do what ever you like
                
     } else {
        //keyboard is hidden
     }
}
0 голосов
/ 13 января 2020

Спасибо, @Gal Machluf Я попробовал ваш метод, но после показа программной клавиатуры нижняя кнопка исчезает. Что мне делать?

[KeyboardVisibilityUtils.kt]

private val onGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener {

    window.decorView.getWindowVisibleDisplayFrame(windowVisibleDisplayFrame)

    val visibleDecorViewHeight = windowVisibleDisplayFrame.height()
    Log.d("debugTest", "visibleDecorViewHeight : $visibleDecorViewHeight")

    if (lastVisibleDecorViewHeight != 0) {

        if (lastVisibleDecorViewHeight > visibleDecorViewHeight + MIN_KEYBOARD_HEIGHT_PX) {

            val currentKeyboardHeight = window.decorView.height - windowVisibleDisplayFrame.bottom
            Log.d("debugTest","decorView height : ${window.decorView.height}, 현재보여지고 있는 크기의 가장 아래 : ${windowVisibleDisplayFrame.bottom}")

            onShowKeyboard?.invoke(currentKeyboardHeight)
        } else if (lastVisibleDecorViewHeight + MIN_KEYBOARD_HEIGHT_PX < visibleDecorViewHeight) {

            onHideKeyboard?.invoke()
        }
    }

    lastVisibleDecorViewHeight = visibleDecorViewHeight
}

[SignUpFragment.kt]

//키보드 가시성 유틸 초기화
    keyboardVisibilityUtils =
        KeyboardVisibilityUtils(activity!!.window,
            onShowKeyboard = {
                keyboardListener?.onShowKeyboard()
            },
            onHideKeyboard = {
                keyboardListener?.onHideKeyboard()
            }
        )

[SignUpActivity.kt]

override fun onShowKeyboard() {
    Log.d("debugTest", "하단버튼을 없앤다.")
    viewDataBinding.run {
        btnNextSignUp.visibility = View.GONE
        viewFooterSignUp.visibility = View.GONE
    }
}

override fun onHideKeyboard() {
    Log.d("debugTest", "하단버튼을 생성한다.")
    viewDataBinding.run {

        btnNextSignUp.postDelayed({
            btnNextSignUp.visibility = View.VISIBLE
            viewFooterSignUp.visibility = View.VISIBLE
        }, 50)
    }
}
...