I have a ViewPager + ActionBar with tabs. I want to make the soft keyboard hide when I \"swipe\" to another tab but I can\'t figure out how.
I\'ve passed in my Activity
I don't use onPageSelected()
because the hide-keyboard animation screws with the swiping animation. Instead use onPageScrollStateChanged()
:
@Override
public void onPageScrollStateChanged(int state)
{
if (state == ViewPager.SCROLL_STATE_IDLE)
{
if (mViewPager.getCurrentItem() == 0)
{
// Hide the keyboard.
((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0);
}
}
}