如何自定义抽屉式导航选择的 XML 布局?

How do you customize an XML layout of a navigation drawer selection?

有人知道怎么做吗?!?

我在网上到处找了3天了,每一个教程都只教你如何制作抽屉,但问题实际上是把东西作为每个选定项目的布局。

请帮忙!

我不确定这是否是您正在寻找的确切答案,但我使用 AppCompat (ActionBarActivity) 库构建了一个导航抽屉。我还在不同屏幕的导航抽屉 XML 中添加了微调器(下拉列表)之类的东西。

注意:在本例中,我实际上以编程方式将条目添加到 XML 中,但 XML 是抽屉的框架。我本质上是在 id externalLinks.

下制作一个垂直线性布局,可滚动的链接列表

免责声明:纯粹主义者 Material 设计人员会注意到我的导航抽屉位于操作栏下方,但我喜欢提供的小汉堡包 -> 箭头图标,不想掩盖它。区别在于actionBarSize的layout_MarginTop。

希望对您有所帮助!

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawerLayout"
    android:background="@color/background"
    >

<!-- The main content view -->
<LinearLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <include layout="@layout/common_toolbar"/>
    <ScrollView
        android:id="@+id/login_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
<!-- There is a bunch of layout that I removed because it is just my app's screen and isn't part of the answer -->
        </LinearLayout>
    </ScrollView>
</LinearLayout>
<!-- The navigation drawer -->
<LinearLayout
    android:layout_marginTop="?attr/actionBarSize"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="1dp"
    android:background="@color/background"
    android:orientation="vertical"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:background="@color/colorAccent"
        />
    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TextView
                android:id="@+id/navMoreTitle" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/navExternal"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                android:paddingLeft="5dp"
                android:paddingStart="5dp"
                android:paddingRight="5dp"
                android:paddingEnd="5dp"
                android:minHeight="30dp"
                android:gravity="center_vertical"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:background="@color/white"
                />
            <LinearLayout
                android:id="@+id/externalLinks" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@color/background"
                >
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>