• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ankri/SwitchCompatLibrary: I backported the ICS Switch (api level 14+) to Froyo ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ankri/SwitchCompatLibrary

开源软件地址(OpenSource Url):

https://github.com/ankri/SwitchCompatLibrary

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource 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>
 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap