【问题标题】:Show toolbar and bottom navigation view again再次显示工具栏和底部导航视图
【发布时间】:2017-11-09 06:38:33
【问题描述】:

在 recyclerView 中上下滚动时,我已经实现了工具栏和 bottomNavigationView 的显示和隐藏功能。 现在我点击recyclerView 项并转到没有recyclerView 的详细信息页面,现在工具栏和bottomNavigationView 也被隐藏了。使它们在此片段中再次可见的任何方法。

main_activity.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="5dp"
        android:theme="@style/ToolbarTheme"
        app:layout_scrollFlags="scroll|enterAlways"
        app:titleTextAppearance="@style/Toolbar.TitleText" />
</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />


<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bottom_navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="@drawable/menu_view"
    android:isScrollContainer="false"
    app:itemIconTint="@drawable/nav_item_color_state"
    app:menu="@menu/my_navigation_items" />

BottomNavigationViewBehaviour.java

public class BottomNavigationViewBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> {

private int height;

@Override
public boolean onLayoutChild(CoordinatorLayout parent, BottomNavigationView child, int layoutDirection) {
    height = child.getHeight();
    return super.onLayoutChild(parent, child, layoutDirection);
}

@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child,
                                   View directTargetChild, View target, int nestedScrollAxes) {
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target,
                           int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    if (dyConsumed > 0) {
        slideDown(child);
    } else if (dyConsumed < 0) {
        slideUp(child);
    }
}

private void slideUp(BottomNavigationView child) {
    child.clearAnimation();
    child.animate().translationY(0).setDuration(50);
}

private void slideDown(BottomNavigationView child) {
    child.clearAnimation();
    child.animate().translationY(height).setDuration(50);
}
}

MainActivity.java

CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mBottomNav.getLayoutParams();
    layoutParams.setBehavior(new BottomNavigationViewBehavior());
    mBottomNav.clearAnimation();
    mBottomNav.animate().translationY(mBottomNav.getHeight()).setDuration(100);

【问题讨论】:

    标签: android android-recyclerview android-toolbar bottomnavigationview


    【解决方案1】:

    您可以使用 AppbarLayout 使用 appbarLayout.setExpand(true) 进行扩展,但这只会显示您的操作栏而不是您的底部导航栏。

    【讨论】:

    • 谢谢! :) 这有助于修复 appbar 而不是底部导航视图。有什么解决办法吗?
    猜你喜欢
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多