导航抽屉中的自定义列表视图

Custom Listview in Navigation Drawer

如何在导航抽屉中自定义 ListView,例如 in the 2nd picture here

您可以使用 Android 设计支持库的 NavigationView(参见:Android Developers Blog)。

有了 NavigationView,您就不必再使用 ListView。您可以简单地使用 menu.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- your content layout -->

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>

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