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

1

15

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.

Hiltan answered 2/4, 2012 at 2:35 Comment(0)
O
32

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" />
Oshea answered 2/4, 2012 at 18:40 Comment(2)
Thanks for answering part 1 of my question :) So there is no way to show the toggle for pre-v14? How much hassle would it be to customize? Also, is it possible to change the default blue color of the switch to something else?Hiltan
Well I think you need to look at the v14 sources and create custom for pre-v14, but I think in normal case you should stick with platform ux e.g. checkbox. It's also less work :p For the 2. part I'm looking for a way to do that too.Oshea

© 2022 - 2024 — McMap. All rights reserved.