Reputation: 1047
I have an edittext in my fragment. To prevent soft keyboard from pushing my view up I tried
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustNothing"
and programmatically i tried onResume and oncreateview methods of fragment
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
Above techniques didn't worked. But when I put scrollview as root view in fragment and put android:isScrollContainer="false" property then above methods are working... How can I make it work without scroll view
Upvotes: 2
Views: 3550
Reputation: 117
If you only want to do this for specific fragments, do this:
val inputMode = (activity as MainActivity).window.attributes.softInputMode
(activity as MainActivity).window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
override fun onDestroy() {
super.onDestroy()
inputMode?.let { (activity as MainActivity).window.setSoftInputMode(it)}
}
Upvotes: 0
Reputation: 1
Setting android:isScrollContainer = "false"
inside the ScrollView worked for me.
According to the documentation, settings "isScrollContainer" to true means that the scroll view can be resized to shrink its overall window so that there is space for an input method.
I suspect what is happening without setting this attribute to false is that the ScrollView is being treated as a scroll container by default and is being resized (shrunk) to allow the input method to appear. Everything outside of the ScrollView is shown because the ScrollView shrinks by as much as is necessary to show the input method and other views on the same hierarchy level.
Upvotes: 0
Reputation: 100
Also, something to consider double-checking is if your fragment's are DialogFragments. Getting the window of my DialogFragment and then setting its soft input resolved my issue where the other solutions did not.
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.
Source:https://developer.android.com/guide/topics/ui/dialogs.html
That being said, DialogFragment's have their own windows that can be set by doing the following in your onCreateDialog method.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = // instantiate your dialog
//Get your dialog's window
Window window = dialog.getWindow();
if (window != null) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
return dialog;
}
Upvotes: 1
Reputation: 259
Use this in onCreateView() of fragment getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
Upvotes: 2