1

我有底部导航栏的活动(通过roughike BottomBar 库)。它看起来像这样: 在此处输入图像描述

当我尝试滚动页面时,底部栏会自动隐藏。所以,我明白了: 在此处输入图像描述

我想避免这种影响。当我只是想滚动内容但所有内容都在屏幕上时,我不想隐藏底栏。

但是如果页面包含的内容不止一个屏幕,那么底部栏必须在滚动时隐藏(现在它可以正常工作了)。

我的代码没有任何滚动监听器,我的 xml 文件如下所示:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".presentation.ui.mainactivity.MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainCord" >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/sliderContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="@color/primary"
            android:theme="@style/ToolbarStyle"
            app:titleTextAppearance="@style/ToolbarStyle" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:visibility="gone" />

    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        app:bb_tabXmlResource="@xml/bottom_bar_tabs"
        app:bb_activeTabColor="@color/white"
        app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab"
        app:bb_inActiveTabAlpha="1"
        app:bb_behavior="shy|shifting" />
</android.support.design.widget.CoordinatorLayout>

我正在为我的问题寻找解决方案,但一无所获。我能做些什么来避免这种影响?

更新:

FAB 在 ViewPager 中。屏幕截图上的选项卡布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/eventCoordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/eventsRecyclerView"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity = "center"
        android:gravity="center" >

        <TextView
            android:id="@+id/emptyText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/secondary_text"
            android:textSize="16sp"
            android:gravity="center"
            android:text="@string/empty_events_text"
            android:drawableTop="@drawable/ic_no_calendar"
            android:drawablePadding="4dp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/createEventText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/create_event_text"
            android:textColor="@color/secondary_text"
            android:textSize="16sp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/createEventButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/primary"
            android:text="@string/create_event"
            android:textSize="16sp"
            android:visibility="gone" />
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/createEvent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:src="@drawable/ic_add_white_24dp"
        style="@style/floating_action_button"
        app:layout_anchor="@id/eventsRecyclerView"
        app:layout_anchorGravity="bottom|end"
        app:borderWidth="0dp"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp" />

    <RelativeLayout
        android:id="@+id/loadingPanel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center" >

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminate="true" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
4

3 回答 3

2

应用程序:bb_behavior="underNavbar"

您在以下代码中遇到问题

<com.roughike.bottombar.BottomBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_gravity="bottom"
    app:bb_tabXmlResource="@xml/bottom_bar_tabs"
    app:bb_activeTabColor="@color/white"
    app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab"
    app:bb_inActiveTabAlpha="1"
    app:bb_behavior="shy|shifting" />

更换

app:bb_behavior="shy|shifting"

app:bb_behavior="underNavbar"

希望这对你有用!

于 2016-11-21T09:30:23.460 回答
0

我有同样的问题,我通过这样做解决了它:

activity_main.xml中将其添加到CoordinatorLayout

android:fitsSystemWindows="true"

浏览器应该是这样的:

<android.support.v4.view.ViewPager
    android:background="@color/colorPrimary"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

在所有Fragments中,它们应该以NestedScrollView开头,并且必须包含(fillViewport):

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context="com.khan.junaid.phonefans.MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fans_list_view"
        />

</android.support.v4.widget.NestedScrollView>

这些设置将使片段可滚动,并且内容将不再隐藏在导航栏按钮后面。

于 2018-02-25T09:16:37.320 回答
0

检查您的清单文件并确保您没有使用全屏主题...但是,您可以使用以下代码在高于 API 19 的 android 上隐藏和显示栏。要隐藏栏,只需更改VISIBLEGONE确保您showNavBar()onCreate()onResume()方法中调用该方法

public void showNavBar() {
        View view = getWindow().getDecorView();
        view.setSystemUiVisibility(View.VISIBLE);
}
于 2016-11-21T10:05:15.597 回答