Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put switch inside action bar on Android

I'm working on a project where I am currently trying to put a switch inside the applications action bar (as in the wi-fi settings : http://tinypic.com/r/2l8vt35/6 )

How can this be done?

like image 267
SweSnow Avatar asked Jul 19 '12 22:07

SweSnow


People also ask

How do I replace my action bar toolbar?

To replace an app's default action bar with a Toolbar : Create a new custom theme and modify the app's properties so that it uses this new theme. Disable the windowActionBar attribute in the custom theme and enable the windowNoTitle attribute. Define a layout for the Toolbar .


1 Answers

Add android:actionLayout to your <item> in your menu XML resource, pointing to a layout XML resource that has your Switch. Then, use getActionView() on the MenuItem to register listeners on changes in the switch.

Note that Switch only works on API Level 14 and higher.

like image 55
CommonsWare Avatar answered Sep 29 '22 07:09

CommonsWare