2017-02-06 15 views
0

私のプロジェクトでフラグメントとアクティビティのフラグメントツールバーを作成しようとしましたが、 ですが、折りたたみツールバーがうまく機能しません。 ありがとうございます。フラグメントとアクティビティで折りたたみツールバーを作成する方法

+0

このソリューションを試しましたか? http://stackoverflow.com/questions/30739806/coordinator-layout-with-toolbar-in-fragments-or-activity – AndroidBeginner

答えて

0

まず、親の親としてAppBarレイアウトを作成する必要があります。この内部にCollapsingToolbarLayoutを追加します。 CollapsingToolbarLayoutの中には、ツールバーの中に、そして最後にツールバーに必要なものを追加します。

 <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

      <android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapsing_toolbar_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:contentScrim="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|enterAlways"> 

<!--This can be anything, here I've added a view pager inside collapsing toolbar--> 

       <android.support.v4.view.ViewPager 
        android:id="@+id/pager_introduction" 
        android:layout_width="match_parent" 
        android:layout_height="192dp" 
        android:fitsSystemWindows="true" 
        app:layout_collapseMode="parallax" 
        tools:listitem="@layout/pager_item" /> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
        app:layout_collapseMode="pin" /> 

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

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

ここでアンドロイド部分は、ツールバーをインスタンス化して設定します。

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

私の場合、ビューページを追加しました。別のアダプタを作成して、そのビューページを作成する必要があります。

関連する問題