Show entire bottom sheet with EditText above Keyboard Show entire bottom sheet with EditText above Keyboard android android

Show entire bottom sheet with EditText above Keyboard


Just reposting @jblejder from this question Keyboard hides BottomSheetDialogFragment since it worked for me, to make it easier for others to find:

The most convenient way that I found to change this is by creating style:

<style name="DialogStyle" parent="Theme.Design.Light.BottomSheetDialog">    <item name="android:windowIsFloating">false</item>    <item name="android:statusBarColor">@android:color/transparent</item>    <item name="android:windowSoftInputMode">adjustResize</item></style>

And set this in onCreate method of your BottomSheetDialogFragment:

override fun onCreate(savedInstanceState: Bundle?) {    super.onCreate(savedInstanceState)    setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)}

This is how it looks on my device:

enter image description here

==== UPDATE ====

As already mentioned in the Comments a few times, you might also need to set the state of the BottomSheetDialog to STATE_EXPANDED like in Nordknight's answer below

dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);  dialog.setOnShowListener(new DialogInterface.OnShowListener() {@Overridepublic void onShow(DialogInterface dialog) {            new Handler().postDelayed(new Runnable() {                @Override                public void run() {                    BottomSheetDialog d = (BottomSheetDialog) dialog;                    FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);                    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);                }            },0);        }    });


This might be a redundant answer. Although just pointing out the issue.If you're using BottomSheetDialogFragment, the only way is to enable the attribute android:windowIsFloating to true. This will enable the whole window to be on top of whatever is trying to take the space behind it.

<style name="BottomSheetDialogThemeNoFloating" parent="Theme.Design.Light.BottomSheetDialog">        <item name="android:windowIsFloating">false</item>        <item name="android:windowSoftInputMode">adjustResize|stateVisible</item></style>

Then in your onCreate() of your dialog, set this style.

override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        // set the window no floating style        setStyle(DialogFragment.STYLE_NORMAL, R.style.AppRoundedBottomSheetDialogThemeNoFloating)}

This is handy for those who frequently use bottom sheets and may want to deal with EditText and soft keyboard overlapping each other.

Note: The class KeyboardUtil by mikepenz has an issue in which on certain phones, the content view with input field is automatically pushed above keyboard despite giving bottom padding to the whole content view supplied.


dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);  dialog.setOnShowListener(new DialogInterface.OnShowListener() {@Overridepublic void onShow(DialogInterface dialog) {            new Handler().postDelayed(new Runnable() {                @Override                public void run() {                    BottomSheetDialog d = (BottomSheetDialog) dialog;                    FrameLayout bottomSheet = d.findViewById(R.id.design_bottom_sheet);                    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);                }            },0);        }    });

This code works fine at Fragment's onCreateView method (thanks for ADM)