Giter Site home page Giter Site logo

switchbutton's Introduction

SwitchButton

Android Arsenal

To get a quick preview, you can get Demo apk in Google Play or Directly download.

This project provides you a convenient way to use and customise a SwitchButton widget in Android.


Change Log

All Change Log

Some attributes are changed in 2.0.0 and you need to update them to the new ones, since the measurement logic has been totally changed. (Default behavior and style does not change.)

因为2.0.0测量逻辑的改变,部分属性已经做了修改,请更新到新的属性。(默认行为和样式并没有变化)

  1. Re-clarify the meaning of some params.
  2. Update the measurement of SwitchButton and the logic becomes more clear, especially the text part.
  3. Support config SwitchButton's size by setting a exact width and height. There are now TWO mainly method to control it's size.
  4. When use SwitchButon in a scrollable view, SwitchButton consume scroll gestures only horizontal. This means the when you want to scroll the scrollable view vertically and start your touch on a SwitchButton, it will not stop you now.
  5. Bug fix.
  1. 重新明确了参数的含义。
  2. 更新了SwitchButton的测量机制,逻辑更加清晰;尤其是文字部分。
  3. 支持设置确定的宽高,来确定SwitchButton的View大小。现在有两种方式可以控制SwitchButton的大小了。
  4. 可滚动的View中的SwitchButton只会消费横向滚动事件。这意味着你可以从SwitchButton开始按下并纵向滚动可滚动View,SwitchButton现在不会阻止你滚动了。
  5. Bug 修复。

Using SwitchButton in your application

In Gradle ​ Add dependencies in build.gradle of your module

dependencies {
    implementation 'com.kyleduo.switchbutton:library:2.1.0'
}

Version 2.1.0 can be pulled from mavenCentral()

Migrate to 2.0.0 (迁移到2.0.0)

ENG

There is a big diagram below to show how SwitchButton measure it self in 2.0.0. It is strongly recommended that you should check it out.

  1. kswBackMeasureRatio has been removed from SwitchButton attributes since it has an ambiguous meaning. I've add the new kswThumbRangeRatio attribute to represent how much multiple the scroll range of thumb than the width of thumb.
  2. kswTextMarginH and kswAutoAdjustTextPosition have been removed from SwitchButton attributes since I updated the measurement logic of text part. And these two attributes do not represent the back meaning well. kswTextThumbInset, kswTextExtra and kswTextAdjust was introduced to represent "how much the text go under thumb", "how much extra space do you want around the text" and "how much to move the text from the center of text area to adjust the text's position". There are all shown on the diagram.
  3. Setters and getters are also changed due to the change of attributes.

CHN

下面有一张图表来解释SwitchButton在2.0.0版本中是如何进行测量的,非常建议你看一看。

  1. kswBackMeasureRatio 属性被移除了,因为名称有歧义。新增加的 kswThumbRangeRatio 属性表示thumb移动区域和thumb宽度的比值。
  2. kswTextMarginHkswAutoAdjustTextPosition 属性被移除了,因为我更新了对文字的测量逻辑,而且这两个属性名称表意不明确。我增加了kswTextThumbInset, kswTextExtrakswTextAdjust 这三个新属性来分别表示“文字在thumb下面的距离”,“额外文字空间”和”文字调节距离“。这些都在图表中有所体现。
  3. setter和getter都跟随属性名称的改变而进行了改变。

Diagram: How SwitchButton Measure

This diagram shows how SwitchButton measure itself and what does those nouns mean. To measure width is much complex than the height, so if you know how to measure width, you know how to measure height. And text measurement and location increase the complexity.

demo_preview


Demo

I create a new demo apk to show you how to style the cute widget and use it. There's some screenshots of the new demo.

demo_preview


Usage

The usage of SwitchButton is just like CheckBox. The basic control APIs of SwitchButton.

  • setChecked(boolean)
  • toggle()

Since SwitchButton has addition animation when checked status changed, there are two addition methods for disable animation for single operation.

  • setCheckedImmediately(boolean): like setChecked but NO animation.
  • toggleImmediately(): like toggle but NO animation.

From version 1.4.1 on, SwitchButton support operation without onCheckedChanged callback. It makes changing state in code more convenient. Using these methods to achieve that feature.

  • setCheckedNoEvent(boolean)
  • setCheckedImmediatelyNoEvent(boolean)
  • toggleNoEvent()
  • toggleImmediatelyNoEvent()

Style

In 1.3.0, I updated the usage of SwitchButton library. To make it more Android way to use, I've combined the thumb and back style each to StateListColor/StateListDrawable. So you are free to create styles in different states.

In xml layout file, you can configure the face of switch button using these attrs.

  • kswThumbDrawable: drawable for thumb
  • kswThumbColor: color for thumb
  • kswThumbMargin: margin from thumb to back, can be negative. maybe cover by single direction margins
  • kswThumbMarginTop: same to kswThumbMargin, just top
  • kswThumbMarginBottom: same to kswThumbMargin, just bottom
  • kswThumbMarginLeft: same to kswThumbMargin, just left
  • kswThumbMarginRight: same to kswThumbMargin, just right
  • kswThumbWidth: width of thumb
  • kswThumbHeight: height of thumb
  • kswThumbRadius: radius of thumb rect, only work with kswThumbColor
  • kswBackRadius: radius of background rect, only work with kswBackColor
  • kswBackDrawable: drawable for background
  • kswBackColor: color for background
  • kswFadeBack: fade background color/drawable when drag or animate between on/off status or not
  • kswAnimationDuration: duration of animation between 2 status
  • kswTintColor: change SwitchButton's style just by one property, all relevant color will be generate automatically. Do not support SwitchButtonMD or other style created by xml resources.
  • kswTextOn: text for checked status.
  • kswTextOff: text for unchecked status.
  • kswTextThumbInset (since 2.0.0): length of the part of text under the thumb.
  • kswTextExtra (since 2.0.0): extra space needed by background besides the actual text width.
  • kswTextAdjust (since 2.0.0): move the text after position text on the center of text area.
  • kswThumbRangeRatio (since 2.0.0): (thumb move range width / thumb's width). float value. see measure diagram
  • kswBackMeasureRatio: (background's width / thumb's width). float value. Removed since 2.0.0
  • kswTextMarginH: horizontal margin of text. Removed since 2.0.0
  • kswAutoAdjustTextPosition: (since 1.4.4) whether auto adjust text position to make them looks centered (NOT really centered) when there are round corners. You should set this to false when you don't need this feature. Removed since 2.0.0

You can alse change the configuration of SwitchButton in code. You can find the api from Demo apk. There's a glance.

private String[] opts = new String[]{
			"setThumbColorRes/setThumbColor",
			"setThumbDrawableRes/setThumbDrawable",
			"setBackColorRes/setBackColor",
			"setBackDrawableRes/setBackDrawable",
			"setTintColor",
			"setThumbMargin",
			"setThumbSize",
			"setThumbRadius (color-mode only)",
			"setBackRadius (color-mode only)",
			"setFadeBack",
			"setBackMeasureRatio",
			"setAnimationDuration",
			"setDrawDebugRect",
			"setText",
	};

Beautiful Apps

If you're using SwitchButton in your app, wish you can email me these infomation of your app and I'll create a list here. And that should be an utmost encouragement to me. :-) [email protected]

App Name Description Markets Developer
headlines.png Headlines Headlines is a news dashboard for your smart TV. market_logo_google_play.pngamazon-underground-app-us-black.png MYSTRAL
lantouzi.png 懒投资 专业安全的投资理财平台 官方网站 懒投资 lantouzi.com
notifications_in_bubble.png Notifications in bubble Access all notifications from a floating bubble. market_logo_google_play.png BestAppzz

License

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

   http://www.apache.org/licenses/LICENSE-2.0

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.

switchbutton's People

Contributors

kyleduo avatar lpmfilho avatar mikeyang01 avatar pborreli avatar wutongke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

switchbutton's Issues

setOnCheckedChangeListener has no effect

Since SwitchButton extends CompondButton, I expect to use setOnCheckedChangeListener to track check state changes. But the implementation of onTouchEvent prevents this, such that we have to track the click event and check the isChecked value instead. Is there any chance you are going to update it?

Btw, thanks for the great component!

setTintColor() makes Thumb get big

Hello!

I am testing changing the tint color programmatically with setTintColor but when I run the app, the thumb turns so big that it doesn't looks nice. I don't know why it changes it size. If i set the tint via xml, is working good.

Do I have to set some parameters up in order to setTintColor work properly?
Thanks!

My XML
<com.kyleduo.switchbutton.SwitchButton android:id="@+id/indicator_switch" android:layout_width="match_parent" style="@style/SwitchButtonMD" app:kswTintColor="@color/teal" android:layout_height="wrap_content" android:layout_weight="1" android:layout_gravity="right" android:gravity="right"/>

My Java:

login_remember_me.setTintColor(getResources().getColor(R.color.red));

Big thumb image

screen shot 2016-05-09 at 2 09 02 pm

BackColor for On and Off

Is there a way to define a BackColor (like green) for the background only for when it's On? The only way I found so far is to programmatically set it to green/gray using the setOnCheckedChangeListener.

SwichButton高度问题

SwichButton的宽高都设置为wrap_content的时候,SwichButton上面和下面都有白色的边距,就像设置了padding_top和padding_bottom一样,而且上下的边距不相等,无法设置SwichButton在水平方向的LinearLayout中垂直居中显示,希望楼主能解决

点击无响应

在ScrollView->LinearLayout->SwichButton的嵌套布局中,SwichButton的左右滑动是ok的,但是点击无响应,跪求解决

can't change color

Hi, first thanks for this great contribution.

I have a problem, i can't modify the color, i have added the color attributes but it stays the same

release jar

can you provider a release jar of this library?

当手指在SwitchButton上面移动,然后move出了SwitchButton的边界,移动到其他控件上面,还能滑动SwitchButton

看了一下代码在move里面没有加边界判断,超出控件自身范围后,应该和UP里面的执行一样的逻辑吧

switch (action) {
            case MotionEvent.ACTION_DOWN:
                catchView();
                mStartX = event.getX();
                mStartY = event.getY();
                mLastX = mStartX;
                setPressed(true);
                break;

            case MotionEvent.ACTION_MOVE:
                float x = event.getX();
                setProcess(getProcess() + (x - mLastX) / mSafeRectF.width());
                mLastX = x;
                break;

            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                setPressed(false);
                nextStatus = getStatusBasedOnPos();
                float time = event.getEventTime() - event.getDownTime();
                if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) {
                    performClick();
                } else {
                    if (nextStatus != isChecked()) {
                        playSoundEffect(SoundEffectConstants.CLICK);
                        setChecked(nextStatus);
                    } else {
                        animateToState(nextStatus);
                    }
                }
                break;

            default:
                break;
        }

以configuration的方式设置样式

我想定制不一样的效果,但是在页面战士的时候,开关的状态会出现错乱,点击一下,会跳过去再跳过来,连续两次.求思路

Demo App can not work in RedMI2(红米2)

Once SwitchButton is placed in ScrollView(activity_use.xml), it can not slide after click and only splash like a button. I imported your project and built the demo app with Android Studio without changing any code.

当把 SwitchButton 放在ScrollView的LinearLayout中时(activity_use.xml),就只能像按钮一样响应点击并且只闪一下,不能自动滑动上面的滑块,也很难把滑块滑走。
在Nexus 6(android 5.1)上也一样,Easy to use中的SwitchButton都不能正常工作。

Not able to set size for iOS switch

I copied and pasted code from your sample into my app, however the switch is appearing kind of huge
screen shot 2016-07-05 at 4 23 23 pm

Is there a way to control the size of the switch? I need it to be smaller.

Request - Gradle

Great Library
Wish To Use It With Gradle.
Can U Add It To Maven?

I use api22 have this problem ,can you help me?

I nill use api23 ;only want to use api22 ~
C:\Users\Administrator\AndroidStudioProjects\ZoneStudio233\Android_Zone_Test\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.0\res\values-v23\values-v23.xml Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

In setOnClickListener,setChecked is bad

First, so sorry my english is very bad.
In my project, I use the SwitchButton, but I meet with a issue.
I write a test for the issues below.

        sbDefault = (SwitchButton) findViewById(R.id.sb_default);
        sbDefault.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {
                sbDefault.setChecked(false);
            }
        });

        final Switch androidSwitch = (Switch) findViewById(R.id.android_switch);
        androidSwitch.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {
                androidSwitch.setChecked(false);
            }
        });

the 'sdDefault' is the SwitchButton, it doesn't work well, otherwise the 'androidSwitch' is android's Switch widget, it works very good.
I hope you can solve this issue.

Share source files for md drawables

Hi,

I would like to be able to colourize the MD-style switch button as well (not just the normal one) However the md style button currently relies on some png files of which I can not change the color (or size for that matter)
Could you share the SVG files that where used to generate those png files?

关于setOnCheckedChangeListener

有没有那种只在状态切换时候的监听,
sb_md_open.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@OverRide
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) startActivity(new Intent(SetOptionActivity.this,MySetPatternActivity.class));
else if(PatternLockUtils.hasPattern(getApplicationContext()))PatternLockUtils.clearPattern(getApplicationContext());
}
});
这样写,刚进入activity会直接走isChecked方法,但是我只是想在手动切换状态时执行。

在onPostExecute里面setChecked无效

你好,这个控件在onPostExecute里面setChecked无效,你可以尝试在doInBackground里面Thread.sleep(4000),然后在onPostExecute里面修改check值

NullPointerException in SwitchButton.drawableStateChanged()

Hi there!

I've got an issue with NullPointerException in SwitchButton.drawableStateChanged() - mConf is not initialized.
When I do android:enabled="false" in XML then drawableStateChanged() is calling before initView(). Because of there is super(context, attrs, defStyle) in constructor of course.

When I use setEnabled(false) for SwitchButton in code all work right.

Switch cropped in SwitchbuttonMD theme

Using SwitchbuttonMD theme for SwitchButton in preview in Android Studio view is cropped too much, probably because of negative margins / measure ratio in styles.

Invalid view:
switch_invalid

Desired view:
switch_valid

However, after launching app SwitchButton displays correctly.

But, when using it in RecyclerView and scrolling down the list, new views are rendered badly (like on the 1st image). We have to scroll up and down again to have it displayed correctly.

NullPointerException

mIsThumbUseDrawable = mThumbDrawable != null;
        mTintColor = tintColor;
        if (mTintColor == Integer.MIN_VALUE) {
            mTintColor = DEFAULT_TINT_COLOR;
        }
        if (!mIsThumbUseDrawable && mThumbColor == null) {
            mThumbColor = ColorUtils.generateThumbColorWithTintColor(mTintColor);
            mCurrThumbColor = mThumbColor.getDefaultColor();
        } else if (!mIsThumbUseDrawable) {
            //noinspection ConstantConditions
            thumbWidth = Math.max(thumbWidth, mThumbDrawable.getMinimumWidth());
            thumbHeight = Math.max(thumbHeight, mThumbDrawable.getMinimumHeight());
        }

if mThumbDrawable ==null
mIsThumbUseDrawable = false

then will execute if (!mIsThumbUseDrawable) {

and then execute mThumbDrawable.getMinimumWidth()

and then throw NullPointerException

# CRASH THREAD: main
03-03 11:12:58.392 4676-4676/com.jdhome E/CrashReport: # CRASH DEVICE: Venue7 3740 ROOTED
03-03 11:12:58.392 4676-4676/com.jdhome E/CrashReport: # RUNTIME AVAIL RAM:236696000 ROM:11026690048 SD:11026690048
03-03 11:12:58.392 4676-4676/com.jdhome E/CrashReport: # RUNTIME TOTAL RAM:968424000 ROM:11357343744 SD:11357343744
03-03 11:12:58.402 4676-4676/com.jdhome E/CrashReport: # EXCEPTION TYPE: java.lang.NullPointerException
03-03 11:12:58.402 4676-4676/com.jdhome E/CrashReport: # EXCEPTION MSG: 
03-03 11:12:58.402 4676-4676/com.jdhome E/CrashReport: # EXCEPTION STACK:
                                                        android.view.InflateException:Binary XML file line #140: Error inflating class com.kyleduo.switchbutton.SwitchButton
                                                       android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                       ......
                                                       cause by:
                                                       java.lang.NullPointerException:
                                                       com.kyleduo.switchbutton.SwitchButton.init(SwitchButton.java:162)
                                                       com.kyleduo.switchbutton.SwitchButton.<init>(SwitchButton.java:78)
                                                       java.lang.reflect.Constructor.constructNative(Native Method)
                                                       java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                       android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                       android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                       android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                       android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                       android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                       android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                       android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                       android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                       com.jdhome.modules.setting.SettingFragment.onCreateView(SettingFragment.java:35)
                                                       android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
                                                       android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                       android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
                                                       android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                       android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
                                                       android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                       android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
                                                       android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
                                                       android.support.v4.view.ViewPager.populate(ViewPager.java:952)
                                                       android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
                                                       android.view.View.measure(View.java:16505)
                                                       android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
                                                       android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                       android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                       android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                       android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                                                       android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                                                       android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                       android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                       android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                                                       android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                                                       android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                       android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                       com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2294)
                                                       android.view.View.measure(View.java:16505)
                                                       android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
                                                       android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
                                                       android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
                                                       android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
                                                       android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
                                                       android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
                                                       android.view.Choreographer.doCallbacks(Choreographer.java:574)
                                                       android.view.Choreographer.doFrame(Choreographer.java:544)
                                                       android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
                                                       android.os.Handler.handleCallback(Handler.java:733)
                                                       android.os.Han
03-03 11:12:58.402 4676-4676/com.jdhome E/CrashReport: #++++++++++++++++++++++++++++++++++++++++++#

how can i set checked without callback?

update 1.2.6
With calling the method setChecked(boolean, false);, you can change the status without invoking the listener.

there is the method setChecked(boolean, false) in the 1.2.6, but no longer in 1.4.0, so what should i do when i want to modify the check status whitout callback?

配合使用 Android 系统自带的 Preference,使用 自定义 SwitchPreference 时会有问题

在我使用 SwitchPreference 结合 SwitchButton 做设置页面时,会出现奇怪的 UI 问题,每次更新 其他 Item 时。SwitchPreference 上的SwitchButton 会自动执行动画一次,
不知道,你有没有让 这个控件 跟 SwitchPreference 结合使用过,其实你可以在 demo 中 加入 设置页面中使用 SwitchButton 的示例,毕竟 这个控件跟 设置界面结合使用 比较多!

https://github.com/jenzz/Android-MaterialPreference

Failed to resolve:com.kyleduo.switchbutton:library:1.2.8

Hi,
I am trying to use this library but I get this error
Failed to resolve:com.kyleduo.switchbutton:library:1.2.8.
Can you please give proper maven url if any and the compile statement. I am using Android Studio and gradle.

Can't set switch color

Thanks for your lib.I set thumbColor to MD switch button,it can't work.

<com.kyleduo.switchbutton.SwitchButton
    android:id="@+id/sb_md"
    style="@style/MaterialDesignStyle" 
    app:onColor="#ff0000"/>

iOS Style Disabled State

Hi,

Thanks for the great help that's provided by your library.
But my requirement to use your library was just to imitate iOS Style Switch button. But unfortunately it seems like I can't get the minor feature of it when the iOS Style Switch button is in Disabled State.

Is there anyway to resolve this? Or have I been doing something wrong?

Bug - Material Design

Hi,
I imported this lib in android studio as module.
When I use MD as style, it generates a big switch button (it look likes the default style but big one)

在某些情况下控件显示不完整

以下是一种复现方式

<com.kyleduo.switchbutton.SwitchButton
                android:id="@+id/sb_custom_miui"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                app:kswBackDrawable="@drawable/miui_back_drawable"
                app:kswBackMeasureRatio="2"
                app:kswThumbDrawable="@drawable/miui_thumb_drawable"
                app:kswThumbHeight="18dp"
                app:kswThumbWidth="18dp" />

Android Studio AVD选Nexus 5x

预览效果是(注意右侧缺了一块)
qq20160524-0 2x

build failure

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jianShu:processDemoDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name_demo) from AndroidManifest.xml:61:9-47
    is also present at [com.kyleduo.switchbutton:library:1.2.10] AndroidManifest.xml:13:9-41 value=(@string/app_name)
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:56:5-739:19 to override

lib project don't add android:label should be better

Switch button with editText

Hi, im trying to use switch button with an edittext inside an adapter.
I have already implemented all the logic to save the pressed state and it works but when i set the switch on, it prevents me from focusing on the other views (Currently two editTexts). When i switch to false, i'm able to focus on the edittexts again.
Can you help me please? Thanks in advance.

BackColor for On and Off

Is there a way to define a BackColor (like green) for the background only for when it's On? The only way I found so far is to programmatically set it to green/gray using the setOnCheckedChangeListener.

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.