2

I want to use the hamburger menu and tabs below. Actually I use the CoordinatorLayout for the hamburger menu and the AppbarLayout (with a toolbar and the Tablayout) for the tabs. Both parts work - but when I combine them, I can't see the hamburger button- but the menu is there, I can swipe it (the bar is there too, but without the button and the activity title).

thats my main xml-file

<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>

the 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" />

and the 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"  />

Mel
  • 23
  • 3

1 Answers1

2

Try this:

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");

EDIT: The problem is happening because you have multiple AppBarLayout and Toolbar in the same layout. Don't include layout="@layout/app_bar_hamburger" in your main.xml. Only include `layout="@layout/app_bar_tabs". And it should all work fine.

Harsh Pandey
  • 831
  • 7
  • 12
  • thanks for your answer - I found the problem now (but actually no solution). I have two toolbars, the toolbar with the title and the button and the toolbar for the tabs - the burger-toolbar is behind the tabs toolbar I'll try some settings, I hope it will work :) – Mel Jul 17 '16 at 20:19
  • That shouldn't happen. The TabLayout should be under the toolbar with the title and the button. Share some code and I should be able to help you figure it out. – Harsh Pandey Jul 17 '16 at 20:30
  • Check edit. Let me know if that doesn't work for you. – Harsh Pandey Jul 18 '16 at 02:40
  • Great! If you need more help, feel free to ask. If this problem is solved, and this answer was helpful, please consider accepting the answer so that this question can be removed from the list of unanswered questions. – Harsh Pandey Jul 18 '16 at 13:15