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?
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With