2017-05-19 100 views
-1
<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/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways"/> 

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


    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/tab_bar" /> 

    <com.whl.handytabbar.HandyTabBar 
     android:id="@+id/tab_bar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:background="@drawable/custom_shadow" /> 

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

回答

2

工具栏位于AppBarLayout内部,可能位于您的CoordinatorLayout内部,因此应如此工作。

AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar); 
     appBarLayout.setExpanded(true, true); 

或者崩溃的工具栏,然后这样的事情应该工作

AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar); 
     appBarLayout.setExpanded(false, true); 
+0

这是一些文档[https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html#setExpanded(boolean)]供参考。 –

0

你需要这个app:layout_behavior="@string/appbar_scrolling_view_behavior"在您的滚动查看下面:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rvToDoList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

,我们需要定义AppBarLayout和View 将滚动之间的关联。向RecyclerView或 添加应用程序:layout_behavior或其他任何能够嵌套滚动的View,例如NestedScrollView。 支持库包含一个特殊字符串资源 @ string/appbar_scrolling_view_behavior映射到 AppBarLayout.ScrollingViewBehavior,用于在此特定视图上发生滚动事件时通知 AppBarLayout。必须在触发事件的视图上建立 行为。

你应该看看This Guide

相关问题