2017-02-21 228 views
2

當可摺疊工具欄展開時它工作良好,但當我向上滾動以使其摺疊到工具欄中時,工具欄僅顯示我的應用程序名稱。我希望它也顯示漢堡切換。如何摺疊摺疊工具欄時導航欄切換?

代碼:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 
} 

回答

0

發生了什麼事是你的工具欄並沒有被告知繪製圖標的標題左側的。當您的工具欄展開後,CollapsingToolbarLayout會告知工具欄有圖標。

所以,如果你希望你的工具欄有標題的左邊的圖標,你可以這樣做:

getSupportActionBar().setDisplayShowHomeEnabled(true); 

你通常並不需要這樣做,因爲活動將告訴動作條如果活動具有父活動,則顯示該圖標。因此,我懷疑你的情況是我們正在談論你的啓動器活動。

希望這會有所幫助。

0

我找到了解決方案。我已將可摺疊工具欄中的工具欄設置爲應該固定的視差。

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