如何隐藏底部TabLayout一旦键盘显示



我使用底部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)。如何实现呢?

注:

我试着听键盘显示事件,并设置TabLayout可见性与mBottomTabLayout.setVisibility(isOpen ? View.GONE : View.VISIBLE);

但是这将隐藏整个ViewPagerTabLayout

将此添加到您想要隐藏TabLayout的activity标签下的manifest:

android:windowSoftInputMode="adjustPan" 

根据@Rahul Sharma的建议,将RelativeLayout更改为LinearLayout后,它可以工作。

然后我使用keyboardvisbilityevent库:

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

最新更新