Wednesday, 12 February 2014

Fragment dialog with scroll view doesn't scroll - solution

There is possibility, you will have scrollview inside dialog fragment plus with many buttons and the view won't move.

To fix it you should do the same thing like with activities by adjusting windowSoftInputMode in dialog theme.

You should set custom theme for your fragment dialog by inheriting current android dialog and adding windowSoftInputMode option:

 <style name="DialogFragmentStyle" parent="@android:style/Theme.Dialog">  
     <item name="android:windowSoftInputMode">stateHidden|adjustResize</item>  
 </style>  

Use your theme in your fragment dialog while creating constructor

 Dialog dialog = new Dialog(getActivity(), R.style.DialogFragmentStyle);  

 public class MyFragmentDialog extends DialogFragment{  
   @Override  
   public Dialog onCreateDialog(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     Dialog dialog = new Dialog(getActivity(), R.style.DialogFragmentStyle);  
     //stuff  
     return dialog;  
   }  
   //... other methods  
 }