使用抽屉和标签的基本android设计
我需要我的主要活动有一个抽屉菜单,在不同的片段之间切换。我还需要主片段有3个选项卡,每个选项卡对应一个不同的片段 对于新的设计支持库,我对如何通过XML实现这种结构感到困惑(因为TabLayout在AppBarLayout中,而保存不同选项卡片段的viewPager则不在其中) 现在我拥有的是切换片段的标签(使用FragmentPageAdapter)和一个不做任何事情的抽屉 以下是主布局的代码:使用抽屉和标签的基本android设计,android,xml,android-layout,android-fragments,drawer,Android,Xml,Android Layout,Android Fragments,Drawer,我需要我的主要活动有一个抽屉菜单,在不同的片段之间切换。我还需要主片段有3个选项卡,每个选项卡对应一个不同的片段 对于新的设计支持库,我对如何通过XML实现这种结构感到困惑(因为TabLayout在AppBarLayout中,而保存不同选项卡片段的viewPager则不在其中) 现在我拥有的是切换片段的标签(使用FragmentPageAdapter)和一个不做任何事情的抽屉 以下是主布局的代码: <android.support.v4.widget.DrawerLayout xmlns:
<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>
克隆此git repo-谷歌i/o sched的源代码,运行该应用程序时,您会发现它具有类似的结构。检查此文件和相关文件,谢谢,但我在相关文件中看不到任何选项卡。我还是不明白这是怎么做到的。正如我所说,我需要主屏幕有3个选项卡,我需要抽屉能够将主屏幕切换到另一个(例如,设置片段)。