Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On/Off Toggle Button in Preferences & Action Bar - Ice Cream Sandwich Style

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.

like image 509
aimango Avatar asked Apr 02 '12 02:04

aimango


People also ask

What is toggle switch button?

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.

Which is the toggle button?

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.

Is toggle left on or off?

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).


1 Answers

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" />
like image 127
user802421 Avatar answered Sep 20 '22 16:09

user802421