小编sly*_*mrc的帖子

如何在材料导航抽屉中添加复选框?

我使用菜单项图标菜单,但我想在所有菜单项中添加复选框.这是我的 drawer_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="all">
    <item
        android:checked="false"
        android:id="@+id/item_navigation_drawer_inbox"
        android:icon="@drawable/ic_inbox_black_24dp"
        android:checkable="true"
        android:title="Inbox" />
    <item
        android:id="@+id/item_navigation_drawer_starred"
        android:icon="@drawable/ic_action_toggle_star"
        android:checkable="true"
        android:title="Starred" />
    <item
        android:id="@+id/item_navigation_drawer_sent_mail"
        android:icon="@drawable/ic_action_content_send"
        android:checkable="true"
        android:title="Sent mail" />
    <item
        android:id="@+id/item_navigation_drawer_drafts"
        android:icon="@drawable/ic_action_content_drafts"
        android:checkable="true"
        android:title="Drafts"
        />
</group>

<item android:title="Subheader">
    <menu>
        <item
            android:id="@+id/item_navigation_drawer_settings"
            android:icon="@drawable/ic_action_content_mail"
            android:title="Settings" />
        <item
            android:id="@+id/item_navigation_drawer_help_and_feedback"
            android:icon="@drawable/ic_action_action_delete"
            android:title="Help and feedback" />
    </menu>
</item>

</menu>
Run Code Online (Sandbox Code Playgroud)

有图标和文字.我还想添加所有这些复选框.

[icon] [some text]  [checkbox]
Run Code Online (Sandbox Code Playgroud)

像这样.

我在代码上使用了材质导航抽屉.

这是我的nav_header.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="192dp"
android:gravity="bottom"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"
    android:background="@drawable/bg_ist_nav_img" />

<LinearLayout
    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

checkbox android navigation-drawer material-design

10
推荐指数
3
解决办法
7945
查看次数