I am referring to the blue ON/OFF styling as seen in the default Android Settings app on ICS phones. It can also be seen here: http://android-developers.blogspot.com/2012/02/android-design-v2-now-with-stencils.html I want to put them in a Preference screen, would I have to use a custom preference widget?
Also, is it easy to put toggle buttons in the Action Bar? It seems to be possible since it is done for Wifi Settings in the default Android Settings on ICS, but it is probably a custom menu item?
Any help is greatly appreciated.
Toggle Switches have an operating lever that can be pushed up and down or left and right to switch an electrical circuit. A “toggle” is a small wooden rod that is used as a clothing fastener in the place of buttons.
A toggle button allows the user to change a setting between two states. You can add a basic toggle button to your layout with the ToggleButton object. Android 4.0 (API level 14) introduces another kind of toggle button called a switch that provides a slider control, which you can add with a Switch object.
Use toggles to change settings For example, a toggle is right control when you want to allow users to turn the Airplane Mode ON or OFF. Toggles are the preferred way to adjust settings on mobile because they take less screen estate (in comparison with two radio buttons).
As easy as:
My xml-v14/preferences.xml
<SwitchPreference
android:key="@string/feature_id"
android:title="@string/feature_title" />
For compatibility:
My xml/preferences.xml
<CheckBoxPreference
android:key="@string/feature_id"
android:title="@string/feature_title" />
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