I have 2 fragments in a ViewPager and I want the window to adjust differently to the soft keyboard on the 2nd fragment. Here's what I'm trying:
@Override
public void onPageSelected(int position) {
if(position == 1){ // desired for 2nd fragment
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
} else { // desired for 1st fragment
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
}
}
Observed behavior:
- Enter 1st fragment and default
softInputMode
is working, as expected. - Swipe to 2nd fragment and breakpoint shows that the
softInputMode
should be set toADJUST_NOTHING
, but everything still behaves like the default. - Swipe back to 1st fragment and it behaves with
ADJUST_NOTHING
. - Swiping back and forth now reveals both fragments to behave like
ADJUST_NOTHING
, even though breakpoints show these calls are being made.
To top it off, I can switch fragments all I want and the input mode will behave as default until I pull up the soft keyboard. Then it starts its migration toward ADJUST_NOTHING
. I'm quite baffled.
I don't have any relevant flags in the manifest, although in my Activity onCreate()
I do set the input mode to SOFT_INPUT_STATE_ALWAYS_HIDDEN
.