0

I need my main activity to have a drawer menu which switches between different fragments. I also need the main fragment have 3 tabs, each for a different fragment.

With the new design support library, I got confused about how to accomplish such structure by XML (Because the TabLayout is inside the AppBarLayout but the viewPager which holds the different Tab fragments is not).

Right now what I have is the tabs switching fragments (using a FragmentPageAdapter) and a drawer that does nothing...

Here's the code of the main layout:

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

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            >

            <TextView
                android:id="@+id/below_menu_btn"
                android:layout_width="0dp"
                android:layout_height="0dp" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways"
                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" />

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

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

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

</android.support.v4.widget.DrawerLayout>
OmriSoudry
  • 361
  • 3
  • 13
  • Clone this git repo https://github.com/google/iosched - source code for google i/o sched, when you run the app, you'll find it has a similar structure. Check this and related files https://github.com/google/iosched/blob/master/android/src/main/res/layout/activity_my_schedule_wide.xml – random Jun 22 '15 at 10:25
  • Thanks but I couldn't see any tabs in that related file. I still don't understand how it is done. As I said, I need the main screen to have 3 tabs and I need the drawer's ability to switch the main screen to another one (for example, the settings fragment). – OmriSoudry Jun 22 '15 at 15:13

0 Answers0