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?

  • “Resource not found” exception while trying to load resource in NotepadV1 sample exercice
  • Draw rounded image with white background using Picasso
  • Android Studio 2.2 : I keep seeing “GPU tools not installed, install now”
  • BTLE (Bluetooth Low energy) development kit - must have proximity profile
  • BlueCove, Laptop, and an Android tablet with Bluetooth
  • Receiving a build error when upgrading to gradle 3.3 and android build tools 2.3.0
  • Any help is greatly appreciated.

    Related posts:

    Show only two digit after decimal
    Read file As String
    Shared preferences inside broadcastreceiver
    Change the background color of CardView programmatically
    How to add a button in android?
    Android - Preventing Application data or files being deleted thru “Clear Data” s...
  • Is discard bad for program performance in OpenGL?
  • Android Emulator Error Message: “PANIC: Missing emulator engine program for 'x86' CPUS.”
  • Failed to create BuildConfig class error message in eclipse
  • RESTful frameworks for Android, iOS…?
  • what is the difference betwenn @id/ and @+id/ in android?
  • KeyStore getEntry return null after change password
  • One Solution collect form web for “On/Off Toggle Button in Preferences & Action Bar – Ice Cream Sandwich Style”

    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" />
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.