【发布时间】:2015-11-15 13:40:30
【问题描述】:
我想在我的应用程序中遵循 Google Play 导航设计。
我认为它应该很简单,但不幸的是 Android Studio 不提供这样的内置布局。我也找不到实现该功能的详细示例。但是我找到了几十个第三方库,但是实现的差异太大,看起来没有共识。
我想获得一个从左侧打开的 NavigationDrawer,并且根据您在 NavigationDrawer 菜单上单击的内容,我还希望在单击第一个时具有选项卡式片段(在片段中使用 TabsLayout 和 ViewPager 实现) NavigationDrawer 项(在工具栏下)。
这是我的代码:
activity_main.xml
`
<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_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true" />
<android.support.design.widget.NavigationView
android:id="@+id/menu_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffff"
android:clickable="true"
app:headerLayout="@layout/navheader"
app:itemBackground="?attr/selectableItemBackground"
app:menu="@menu/menu_navigation" />
</android.support.v4.widget.DrawerLayout>
fragment1.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tabanim_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/tabanim_appbar"
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/tabanim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabanim_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/tabanim_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
您找到解决方案了吗?我有同样的问题。
-
@PauloRodrigues 还没有!
标签: java android android-fragments android-design-library androiddesignsupport