【发布时间】: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