Activity with fragments does not resize when the keyboard opens

Use this in onCreateDialog in BottomSheetFragment / Dailogfragment

KeyboardUtil(getActivity(), view);

or

For fragment use

new KeyboardUtil(this, findViewById(R.id.fragment_container));

by using this Util class

https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java

Credit:Mikepenz


When the soft keyboard appears on the screen, the amount of space available for the application's UI reduces. The system makes decision on how to organize the available space between the application's UI and soft keyboard.

  • If the window content contains ListView, ScrollView, the application's window is resized provided all the content is visible.
  • If re-sizing is not feasible, pan and scan approach is used, which simply involves scrolling the application's window so that the currently focused view is visible.

Since your layout does not contain any ListView, ScrollView, re-sizing is ruled out.

The window's root view is a FrameLayout to which you were originally adding LinearLayout. Since LinearLayout does not support scrolling, pan and scan approach is also ruled out. Hence wrapping the layout inside ScrollView solves the scrolling issue.

You can refer Android Developers blog for more details.

Update 1:

OP was able to solve the issue, as indicated in this answer. The issue was happening due to one fragment overlaying another fragment after animation and the parent of these Fragment's was a LinearLayout. For overlay purpose, you need to use RelativeLayout or FrameLayout only.


To change the mode to “resize” at the following statement to your activity in “AndroidManifest.xml”.

 <activity android:name=".ActivityName"
        android:windowSoftInputMode="adjustResize">

and please remove the complexity of LinearLayout ( means you are using multiple level of LinearLayout ) instead of that you can use RelativeLayout also .. using this you can easily set Layout as you want .. try it that also hope your problem may rectifier

I hope this helps.


You can use this code in your Fragment also

This code provide help for resize view

public static class MyDialog extends DialogFragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Dialog layout inflater code
    // getDialog() need to be called only after onCreateDialog(), which is invoked between onCreate() and onCreateView(). 
      getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |     WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
   // return view code
  }
}