Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getWindow().setSoftInputMode not working as expected

In my Android project I want the softInputMode for just one fragment to be adjustPan.

Adding the following line to my manifest (inside the activity) works as expected:

android:windowSoftInputMode="adjustPan"

But following lines in my fragment do nothing:

@Override
public void onResume() {
   super.onResume();
   getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}

@Override
public void onPause() {
    super.onPause();
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
}

Any ideas why that is and what could be done to fix?

like image 802
Budius Avatar asked Dec 10 '13 09:12

Budius


2 Answers

You are setting the soft input mode for the activity, i'm not sure if it will work but try:

myFragment.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

EDIT:

I suppose you are working with the onPause and onResume of the fragment, have yout tried using the ones of the parent activity? The result might be the same thou, because some times they are connected.

like image 196
Ayoub Avatar answered Nov 20 '22 09:11

Ayoub


Try to also set the android:windowSoftInputMode="adjustPan" in your Manifest. I know it looks redundant to set the soft input mode in the manifest and in your code but that's the only way it worked for me.

like image 20
Rob Avatar answered Nov 20 '22 08:11

Rob