7

Can any one just tell me how to add a toggle button to android material design navigation view?

Items are added from menu items

drawer_menu_items.xml

<group android:checkableBehavior="single">

    <item
        android:id="@+id/inbox"
        android:checked="false"
        android:icon="@drawable/ic_inbox_black"
        android:title="@string/inbox_string" />

    <item
        android:id="@+id/starred"
        android:checked="false"
        android:icon="@drawable/ic_star_black"
        android:title="@string/starred_string" />

    <item
        android:id="@+id/sent_mail"
        android:checked="false"
        android:icon="@drawable/ic_send_black"
        android:title="@string/sent_mail_string" />

    <item
        android:id="@+id/drafts"
        android:checked="false"
        android:icon="@drawable/ic_drafts_black"
        android:title="@string/draft_string" />


    <item
        android:id="@+id/allmail"
        android:checked="false"
        android:icon="@drawable/ic_email_black"
        android:title="@string/all_mail_string" />

How to add item or how to add toggle button like in image shown: enter image description here

asad.qazi
  • 2,449
  • 3
  • 23
  • 35

2 Answers2

0

Try to put this android:checkable="true" in the item code

Diego
  • 1,488
  • 1
  • 13
  • 13
0
What you can do is take 2 images of checkbox, one for checked and other for unchecked.
The onclick you may toggle between images, it will give simulation of checkbox. 

also you must be using drawer layout for navigation menu 
xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/AlertDialog.AppCompat.Light"
    android:fitsSystemWindows="true">


Codebehind

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                mDrawerLayout.closeDrawers();
Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17