Varying windowSoftInputMode for fragments inside the viewpager

Android

Android Problem Overview


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!

Android Solutions


Solution 1 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCalvin ParkView Question on Stackoverflow
Solution 1 - AndroidMoxorView Answer on Stackoverflow