2015-12-15 16 views
1

我正在使用Android設計支持庫來獲取導航抽屜模式。我有以下主要活動佈局:當從片段設置工具欄時,沒有用於DrawerLayout的「漢堡包」圖標

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res/pl.dzielins42.skinflint.android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="http://schemas.android.com/apk/res-auto" 
    tools:ignore="MergeRootFrame" > 

    <!-- The main content view --> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <!-- The navigation drawer --> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/drawer_navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/view_nav_drawer_header" 
     app:menu="@menu/drawer" /> 

</android.support.v4.widget.DrawerLayout> 

container佈局是我膨脹我的片段。一些片段在其佈局中有Toolbar。我使用導航抽屜在這些片段之間移動。此外,分別使用Toolbar片段我將其設置爲使用setSupportActionBar活動的動作條,後來

supportActionBar.setDisplayHomeAsUpEnabled(true); 
supportActionBar.setHomeButtonEnabled(true); 

的問題是,在第一片段中的「漢堡包」被適當地顯示的圖標(在活動的onCreate充氣),但在將片段更改爲Toolbar的另一個片段後,圖標變爲標準後退箭頭。

我試圖通過使用ActionBarDrawerToggle(v7)並在onDrawerClosed中調用syncState來解決此問題。這部分修復了這個問題,因爲「漢堡包」圖標已設置,但只有在抽屜完全關閉後才能進行修復,因此在關閉時後退箭頭圖標可見。

有人可以提供更好的解決方案嗎?

回答

0

設置ActionBarDrawerToggle正確:

mDrawerToggle.setDrawerIndicatorEnabled(true); 
相關問題