1

I am using bottom TabLayout with ViewPager above the tabs, XML listed below:

<RelativeLayout
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/toolbar_wrapper"
        layout="@layout/toolbar_main" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs_bottom_main"
        style="@style/AppTabLayout"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_alignParentBottom="true"
        app:tabGravity="fill" />

    <View
        android:id="@+id/view_black_line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@id/tabs_bottom_main"
        android:background="@android:color/black" />

    <NonSwipableViewPager
        android:id="@+id/view_pager_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/view_black_line"
        android:layout_below="@id/toolbar_wrapper"
        android:background="@android:color/white" />

</RelativeLayout>

When the keyboard shows up, the whole View pushed up, I would like to hide the bottom TabLayout only (but keep the ViewPager above) once the keyboard shows up. How to achieve it?

P.S.

I have tried listening the keyboard show up event and set TabLayout visibility with mBottomTabLayout.setVisibility(isOpen ? View.GONE : View.VISIBLE);

But this will hide the whole ViewPager together with the TabLayout.

chubao
  • 5,871
  • 6
  • 39
  • 64

2 Answers2

2

Add this to your manifest under activity tag in which you want to hide the TabLayout:

android:windowSoftInputMode="adjustPan" 
Diego Rafael Souza
  • 5,241
  • 3
  • 23
  • 62
r.pratap
  • 46
  • 1
  • 3
1

It works after I change RelativeLayout to LinearLayout according to @Rahul Sharma's advice.

Then I used the KeyboardVisibilityEvent library:

KeyboardVisibilityEvent.setEventListener(this,
            new KeyboardVisibilityEventListener() {
                @Override
                public void onVisibilityChanged(boolean isOpen) {
                    mBottomTabLayout.setVisibility(isOpen ? View.GONE : View.VISIBLE);
                }
            });
chubao
  • 5,871
  • 6
  • 39
  • 64