【问题标题】:Android Kotlin: Bottom Sheet Dialog keyboard overlap the buttonAndroid Kotlin:Bottom Sheet Dialog 键盘与按钮重叠
【发布时间】:2021-06-09 09:24:18
【问题描述】:

如何在按钮下输入键盘?

片段

class ForgotPasswordBtmSheet : BottomSheetDialogFragment() {

private lateinit var binding: ForgotPasswordBtmSheetBinding

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {

    // Binding
    binding = ForgotPasswordBtmSheetBinding.inflate(inflater, container, false)
    val view = binding.root


    // Dialog
    dialog?.setOnShowListener {
        val mDialog = it as BottomSheetDialog
        val bottomSheetInner = mDialog.findViewById<View>(R.id.design_bottom_sheet)
        if (bottomSheetInner != null) {
            BottomSheetBehavior.from(bottomSheetInner).state =
                BottomSheetBehavior.STATE_EXPANDED
        }
    }


    return view
}

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/btm_sheet_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
tools:context=".auth.ForgotPasswordBtmSheet">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:background="@color/androidBG"
    android:orientation="vertical">

    <TextView
        style="@style/TextViewTheme"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/form_forgot_password"
        android:textSize="@dimen/text_subject" />

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <TextView
        style="@style/TextViewTheme"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/act_chg_password_remark"
        android:textSize="@dimen/text_small" />


    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/edtV_email_layout"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="@dimen/edt_width"
        android:layout_height="@dimen/edt_height"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:hint="@string/act_email">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edtV_email"
            style="@style/EditTextTheme"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inputType="textEmailAddress" />

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


    <Button
        android:id="@+id/btn_submit"
        style="@style/ButtonTheme"
        android:layout_width="@dimen/button_block_width"
        android:layout_height="@dimen/button_height"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:text="@string/app_button_submit" />

</LinearLayout>

【问题讨论】:

    标签: android kotlin android-fragments android-dialogfragment bottom-sheet


    【解决方案1】:

    我认为您需要在AndroidManifest 中的活动中添加adjustResize 标志。有以下两个主要标志。

    调整大小 Activity 的主窗口总是会调整大小,以便为屏幕上的软键盘腾出空间。

    调整平移 Activity 的主窗口没有调整大小来为软键盘腾出空间。相反,窗口的内容会自动平移,因此当前焦点永远不会被键盘遮挡,用户始终可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

    所以我建议你使用adjustResize,这似乎是你想要的。如果没有,您可能还想尝试一次adjustPan

    <activity android:windowSoftInputMode="adjustResize"> </activity>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多