Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A backport of the Switch widget ( that was introduced on Android 4. This port works on Android 2.1+.
Branch: master
Pull request Compare This branch is 84 commits behind BoD:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Android Switch Widget Backport

A backport of the Switch widget ( that was introduced on Android 4.

This port works on Android 2.1+.

How to use

This is an Android library project, you have to add it as a dependency to your project (please see to know how to do that.)

Once you have done that, have a theme for your application (or Activity), that declares the switchStyle item to be one of the two possible themes: either Widget.Holo.CompoundButton.Switch (dark) or Widget.Holo.Light.CompoundButton.Switch (light).

The simplest way to do that is to create a themes.xml file in your project's res/values folder with this contents:

    <?xml version="1.0" encoding="utf-8"?>

        <style name="Theme" parent="@android:Theme">
            <item name="switchStyle">@style/Widget.Holo.CompoundButton.Switch</item>


Then in your layout xml files you can use the widget like this:

        android:layout_height="wrap_content" />


The code was copied directly from the Android 4.0.3 (API 15) source code, then slightly tweaked by myself ( to make it run on 2.1+. The few modifications I made are documented in the code (look for 'XXX' comments).


Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Something went wrong with that request. Please try again.