I'm trying to show a BottomSheetDialogFragment
with a few EditText
fields for the user to enter information. I want to show it directly above the keyboard, but it keeps covering up the contents.
This is what happens when I bring up the BottomSheetDialogFragment
, you can see it's selecting Card Number
EditText
, but covering the other content.
Ideally, this is what I'm looking for, you can see both EditTexts
, and the padding of the View.
I've tried a lot of solutions revolving around windowSoftInputMode
, but nothing seems to work. I've set it to adjustResize
for the parent Activity
and the actual BottomSheetDialogFragment
via
dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
And I've also tried modifying my layout, changing it from a FrameLayout
, to a ScrollView
to a CoordinatorLayout
to see if that had any effect on the position of the layout, but nothing seems to work.
If anyone knows how to accomplish this, that would be greatly appreciated, thank you.
Sometimes, you need to change the layout when the soft keyboard appeared on the screen. You can fix this by adding a line of code into the AndroidManifest. xml file within the relevant activity section.
HIDE_IMPLICIT_ONLY, 0); Here pass HIDE_IMPLICIT_ONLY at the position of showFlag and 0 at the position of hiddenFlag . It will forcefully close soft Keyboard.
Maybe a late answer but would probably help.
Nothing else worked for me. But this solution is working
Inside styles:
<style> // main theme <item name="bottomSheetDialogTheme">@style/BottomSheetDialogTheme</item> ........ // rest of the code </style> <style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog"> <item name="bottomSheetStyle">@style/AppModalStyle</item> <item name="android:windowIsFloating">false</item> <item name="android:windowSoftInputMode">adjustResize</item> <item name="android:statusBarColor">@android:color/transparent</item> </style>
Here android:windowIsFloating
should be false & android:windowSoftInputMode
must be adjustResize
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal"> <item name="android:background">@drawable/rounded_corner_dialog</item> </style>
Note: This part is optional but if things don't work perfectly then Wrap layout inside NestedScrollView
<androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <--Rest of the layout--> </androidx.core.widget.NestedScrollView>
On some devices this solution wasn't enough. Adding this to code solved my problem completely.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) dialog?.setOnShowListener { val dialog = it as BottomSheetDialog val bottomSheet = dialog.findViewById<View>(R.id.design_bottom_sheet) bottomSheet?.let { sheet -> dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED sheet.parent.parent.requestLayout() } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With