键盘出现后如何隐藏底部 TabLayout?

How to hide bottom TabLayout once keyboard shows up?

我使用底部 TabLayout,选项卡上方 ViewPager,下面列出 XML:

<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>

当键盘出现时,整个View向上推,一旦键盘出现,我只想隐藏底部TabLayout(但保留上面的ViewPager) .如何实现?

P.S.

我试过监听键盘显示事件并使用 mBottomTabLayout.setVisibility(isOpen ? View.GONE : View.VISIBLE);

设置 TabLayout 可见性

但这会隐藏整个 ViewPager 连同 TabLayout

根据@Rahul Sharma 的建议,我将RelativeLayout 更改为LinearLayout 后就可以使用了。

然后我使用了 KeyboardVisibilityEvent 库:

KeyboardVisibilityEvent.setEventListener(this,
            new KeyboardVisibilityEventListener() {
                @Override
                public void onVisibilityChanged(boolean isOpen) {
                    mBottomTabLayout.setVisibility(isOpen ? View.GONE : View.VISIBLE);
                }
            });

将此添加到清单中要隐藏 TabLayout 的 activity 标记下:

android:windowSoftInputMode="adjustPan"