Varying windowSoftInputMode for fragments inside the viewpager

I have a ViewPager with 2 different fragments. For the first fragment, I would like to define it so that it does not resize upon the soft keyboard opening. For the second fragment, I would like to have it resize.

Setting the android:windowSoftInputMode="adjustPan" inside the manifest will work for both fragments, but I want to vary it between the two.

What I've done after google searches :

    // create ContextThemeWrapper from the original Activity Context with the custom theme
    Context context = new ContextThemeWrapper(getActivity(), R.style.NoResize);
    // clone the inflater using the ContextThemeWrapper
    LayoutInflater localInflater = inflater.cloneInContext(context);
    // inflate using the cloned inflater, not the passed in default
    return localInflater.inflate.inflate(R.layout.my_layout,container,false);

I've custom defined the theme to be :

<style name="NoResize" parent="@style/AppTheme">
    <item name="android:windowSoftInputMode">adjustPan</item>
</style>

The activity is defined with default windowSoftInputMode which resizes the views when softkeyboard opens up.

Will be working on this until it gets solved but if anyone else has this problem and solved it, it would be awesome to hear any thoughts.

Thanks!


Solution 1:

You can call on each onCreateView

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

check http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#SOFT_INPUT_ADJUST_RESIZE

In my case, this doesn't solve the problem, because I have a transparent Fragment (a chat window) which I need to resize and the fragment on the bottom shouldn't. but I think it could be useful to you.