I need to put Switch inside item in navigation drawer. I'm using new design support library, but I cannot find if it is posibble at all. When using
android:checkable
item is just full selected and that is not what I wish.
This is screenshot of what I really want. Is that possible to achieve that?
You should be able to.
Your navigation drawer view can be a
LinearLayout
, and inside that, you can include yourNavigationView
and anotherViewGroup
adding the switches.One way I have found of doing this would be to use setActionView on the menuItem you want:
Probably want a click listener as well to change the state of the Switch:
I haven't tried, but you could probably use android:actionLayout="@layout/switch_layout" in xml and point to a custom layout you created.
Also could try using an ActionProvider which might offer a little more robustness. I haven't tried this method either though.
simply yes you can do this easily, i will post my code so you can implement it
and the Main Activity Layout should be :
And here's a step by step tutorial for Navigation Drawer using Design Library
Your menu item for the navigation drawer:
and the layout for that item:
None of the answers seems to be complete so after some more research here is what I came up with:
drawer_switch.xml:
drawer_menu.xml:
DrawerActivity.java:
DrawerActivity.java:
I did something like this.