DialogFragment not resizing when keyboard shown
Be sure that the layout is inside a scroll view:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-->your layout here
</ScrollView>
and follow Dirk comment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_text_editor, container);
//add this line
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//[add more custom code...]
return view;
}
I just use the following line in my DialogFragment:
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
And nothing else, see here full example:
public class TextEditor extends DialogFragment {
public TextEditor () {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_text_editor, container);
//set to adjust screen height automatically, when soft keyboard appears on screen
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//[add more custom code...]
return view;
}
}
Set the windowSoftInputMode
property to adjustNothing
in the AndroidManifest.xml
of the activities that use the dialog fragment.
<activity
...
android:windowSoftInputMode="adjustNothing">
...
and onCreateDialog
to hide the soft input:
...
Dialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
return dialog;
}
FYI: https://developer.android.com/training/keyboard-input/visibility.html#ShowOnStart