android - 来自支持库与设计库的抽屉导航

标签 android navigation-drawer material-design android-support-library android-design-library

<分区>

Support Library Features 中所述页; v4 支持库 通过添加 DrawerLayout 添加了对Navigation Drawers 的支持,Design Support Library 添加了对 Navigation 的支持通过添加 NavigationView(作为对作为依赖项的 DrawerLayout 的补充)的抽屉。

有很多教程如何仅使用 v4 支持库创建抽屉导航,例如Google page on Navigation Drawer .

由于设计支持库添加了对 API 级别 7 的支持,因此推荐和首选的创建抽屉导航的方法是什么。差异在哪里?是否存在设计差异?

最佳答案

what is the recommended and preferred way to create a Navigation Drawer. Where are the differences? Are there design differences?

实际上,这些并没有什么大的区别。例如,As Google医生说:

http://developer.android.com/training/implementing-navigation/nav-drawer.html

For example, the following layout uses a DrawerLayout with two child views: a FrameLayout to contain the main content (populated by a Fragment at runtime), and a ListView for the navigation drawer.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

但是在Support Library ,您可以使用 NavigationView 轻松实现此目的当然,标准 Material 设计指南是这样的:

<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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!--Contents like Coordinator Layout-->

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        app:menu="@menu/drawer" />
    <!--Here is the Drawer menu-->

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

在这种情况下,我们使用了 app:menu="@menu/drawer"通过一种简单易行的方法来实现这一点,在上面的代码中,他们使用了 <ListView .

就这些。

关于android - 来自支持库与设计库的抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34838122/

相关文章:

android - 无法创建签名 APK

android - 是否可以在 Android 中使用后台服务检查 "Contacts"和 "Messaging"应用程序状态?

android - 如何清除 View 中所有可选元素的焦点?

android - 使用 Jetpack Compose 中的抽屉导航在可组合项之间导航

polymer - 元素深度与 polymer - Material 设计

java - 内部类不能有静态声明 - public static final String[]

android - 流的乐趣,转换为实时数据时为空

适用于较低 API 的 Android Material Design 抽屉导航

javascript - 在 MaterializeCSS 中滚动时更改导航栏固定位置

android - 如何以编程方式在 CoordinatorLayout 中滚动 NestedScrollView?