0

スクロールアップ中にアクションバーを非表示にして表示しようとしています。私はCoordinatorLayoutに関するいくつかのチュートリアルを続けていますが、動作させることができません。Androidスクロールアップ/ダウン時のアクションバーの表示/非表示

ここではレイアウトが

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

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="scroll|enterAlways" /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:tabTextAppearance="@style/menuTheme" 
     app:tabIndicatorHeight="4dp" 
     app:tabMode="scrollable" 
     app:layout_scrollFlags="scroll|enterAlways" 
     /> 
</android.support.design.widget.AppBarLayout> 
<android.support.v4.widget.DrawerLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_layout" > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 


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

    </LinearLayout> 
    <fragment 
     android:id="@+id/fragment_navigation_drawer" 
     android:name="com.musicplayer.mp3player.activities.FragmentDrawer" 
     android:layout_width="@dimen/nav_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_navigation_drawer" 
     tools:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 
</android.support.design.widget.CoordinatorLayout> 

だここで私はアクションバーのセットアップに使用したコードです。

mToolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(mToolbar); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 
+0

https://labs.ribot.co.uk/exploring-the- new-android-design-support-library-b7cda56d2c32#.45k164x5s –

答えて

0

それが行動を持っているのでViewPagerのようにレイアウトツリーを変更、CoordinatorLayoutの直接の子でなければなりません:

DrawerLayout 

    CoordinatorLayout 

     AppBarLayout 

     ... 

     /AppBarLayout 

     ViewPager (with behavior) 

    /CoordinatorLayout 

/DrawerLayout 
関連する問題