2017-05-19 97 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

相關問題