键盘隐藏BottomSheetDialogFragment

键盘下方有更多的字段。 这发生在我更新支持库时。 我知道这是Kotlin,但它看起来几乎与Java相同。 我该如何解决这个问题?

这是它的样子:

在这里输入图像说明

我的代码:

class ProjectsEditBottomSheetFragment(val privateID: String, val publicID: String) : BottomSheetDialogFragment() { private val mBottomSheetBehaviorCallback = object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss() } } override fun onSlide(bottomSheet: View, slideOffset: Float) { if (slideOffset < -0.15f) { dismiss() } } } override fun setupDialog(dialog: Dialog, style: Int) { super.setupDialog(dialog, style) val view = View.inflate(context, R.layout.projects_edit_sheet, null) dialog.setContentView(view) dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) val params = (view.parent as View).layoutParams as CoordinatorLayout.LayoutParams val behavior = params.behavior if (behavior != null && behavior is BottomSheetBehavior) { behavior.setBottomSheetCallback(mBottomSheetBehaviorCallback) } // Get and set values val realm = Realm.getDefaultInstance() val realmObject = realm.where(ProjectsRealmObject::class.java) .equalTo("privateID", privateID) .findFirst() realm.beginTransaction() view.title_input.text = SpannableStringBuilder(realmObject.title) view.description_input.text = SpannableStringBuilder(realmObject.description) view.public_checkbox.isChecked = realmObject.isPublic realm.commitTransaction() // Keyboard view.title_input.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> if (hasFocus) { (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(view.title_input, InputMethodManager.SHOW_FORCED) } else { (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.title_input.windowToken, 0) } } view.description_input.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> if (hasFocus) { (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(view.description_input, InputMethodManager.SHOW_FORCED) } else { (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.description_input.windowToken, 0) } } // Click listners view.public_layout.setOnClickListener { view.public_checkbox.toggle() } view.cancel.setOnClickListener { view?.hideKeyboard() dismiss() } view.save.setOnClickListener { view?.hideKeyboard() // Save to realm realm.beginTransaction() realmObject.title = if (view.title_input.text.toString() == "") getString(R.string.unnamed) else view.title_input.text.toString() realmObject.description = view.description_input.text.toString() realmObject.isPublic = view.public_checkbox.isChecked realmObject.synced = false realmObject.updatedRealm = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()).toString() + "" realm.commitTransaction() ProjectsSync(context) toast("Sparat") dismiss() } } } 

XML:

                

添加到你的风格

  

然后在你的底部工作表对话框的onCreate()添加

 setStyle(DialogFragment.STYLE_NO_FRAME, R.style.DialogStyle); 

也不要忘记添加到对话框的setupDialog()方法

 dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);