Giter Club home page Giter Club logo

switchcompatlibrary's Introduction

Quick note

Sadly I do not have the time to maintain the code any longer. Additionally I have not worked with Android for quite some time now. If you want to have a backport of the switch, please have a look at this project: https://github.com/Prototik/HoloEverywhere

##Switch for Froyo, Gingerbread & Honeycomb## A little while ago I started my own custom Switch button for Gingerbread. I wanted to have a switch button that always displays the texts on the left and right side. Since the standard Switch only shows the text from the currently selected side, I had to code my own version, which you can check out here: http://ankri.de/switch-button-for-android-2-3-gingerbread/

Unfortunately it isn't perfect. You cannot disable it for example, because I didn't need it in my use case. After I got some feedback, I decided to do a complete backport of the original Switch button, which was fairly easy! I just copied the code and edited some lines.

I present to you the backport of the Switch button. Which has two minor limitations

  • the accessibility functionality doesn't work with the Switch
  • the Switch does not have RTL support

Minor bug

Yeah. Unfortunately there is a minor bug aswell. For some reason the OnCheckedChangeListener is only called when the Switch has an OnClickListener. As a workaround I added an OnClickListener in the constructor of the Switch, so you don't have to worry about it.

Usage

There are two projects. The library and the demo project. You can use the library project just like any other library project.

Just download the project. If you’re using the Eclipse Development Environment with the ADT plugin version 0.9.7 or greater you can include the SwitchCompatLibrary as a library project. Create a new Android project in Eclipse using the SwitchCompatLibrary folder as the existing source. Then go to your project and in your project properties, add the created project under the ‘Libraries’ section of the ‘Android’ category.

To use the Switch you have to configure your theme. There are several ways!

1. When not using any custom theme

Go to your AndroidManifest.xml and edit the theme to this line:
android:theme="@style/AppThemeDark"
for the dark theme or to:
android:theme="@style/AppThemeLight"
for the light theme.

2. When using a custom theme

Go to your styles.xml and make either AppThemeDark or AppThemeLight the parent theme:
<style name="AppTheme" parent="AppThemeLight" />

3. When using a custom theme and depending on a different parent like ActionBarSherlock

Add the two lines to the style your styles.xml for the light theme
<style name="AppTheme" parent="Theme.Sherlock.Light">
  <item name="switchStyle">@style/switch_light</item>
	<item name="textAppearance">@style/TextAppearance</item>
</style>
  Or add the two lines to the style your styles.xml for the dark theme
<style name="AppTheme" parent="Theme.Sherlock">
	<item name="switchStyle">@style/switch_dark</item>
	<item name="textAppearance">@style/TextAppearance</item>
</style>
 

switchcompatlibrary's People

Contributors

ankri avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.