2016-07-15 48 views
1

我想使用下面的漢堡菜單和標籤。其實我使用漢堡包菜單的CoordinatorLayout和標籤的AppbarLayout(帶有工具欄和Tablayout)。這兩個部分都可以工作 - 但是當我把它們合併時,我看不到漢堡包按鈕 - 但菜單在那裏,我可以滑動它(酒吧也在那裏,但沒有按鈕和活動標題)。使用標籤時缺少漢堡包菜單按鈕?

這就是我的主XML文件

<include 
    layout="@layout/app_bar_hamburger" /> 

<include 
    layout="@layout/app_bar_tabs"/> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_hamburger" 
    app:menu="@menu/activity_hamburger_drawer" /> 

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

的app_bar_hamburger:

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

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar_hamburger" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

<include layout="@layout/content_hamburger" /> 

和app_bar_tabs

<android.support.design.widget.AppBarLayout 
    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_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 
</android.support.design.widget.AppBarLayout> 

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

回答

1

試試這個:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // use whatever id you have for your toolbar 
setSupportActionBar(toolbar); 

getSupportActionBar().setHomeButtonEnabled(true); 
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer); 
getSupportActionBar().setTitle("title"); 

編輯:問題發生,因爲你有多個AppBarLayout,並在相同的佈局Toolbar。不要在您的main.xml中包含layout="@layout/app_bar_hamburger"。只包含`layout =「@ layout/app_bar_tabs」。它應該都可以正常工作。

+0

感謝您的回答 - 我現在發現問題(但實際上沒有解決方案)。我有兩個工具欄,帶有標題和按鈕的工具欄以及選項卡的工具欄 - 漢堡 - 工具欄位於選項卡工具欄後面 我會嘗試一些設置,我希望它能工作:) – Mel

+0

那不應該發生。 TabLayout應該在標題和按鈕的工具欄下。分享一些代碼,我應該能夠幫助你弄明白。 –

+0

我已將代碼添加到問題 – Mel