Skip to content

Commit 6b43433

Browse files
committed
feat. append color settings
1 parent c9255d1 commit 6b43433

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

switchbutton/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44

5-
version = "1.0.1"
5+
version = "1.0.2"
66
group = "ch.ielse" // Maven Group ID for the artifact,一般填你唯一的包名
77
def siteUrl = 'https://github.com/iielse/SwitchButton' // 项目的主页
88
def gitUrl = 'https://github.com/iielse/SwitchButton.git' // Git仓库的url
@@ -15,8 +15,8 @@ android {
1515
defaultConfig {
1616
minSdkVersion 10
1717
targetSdkVersion 23
18-
versionCode 1
19-
versionName "1.0.1"
18+
versionCode 2
19+
versionName "1.0.2"
2020
}
2121
buildTypes {
2222
release {

switchbutton/src/main/java/ch/ielse/view/SwitchView.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class SwitchView extends View {
4949
protected int colorOff;
5050
protected int colorOffDark;
5151
protected int colorShadow;
52+
protected int colorBar;
53+
protected int colorBackground;
5254
protected boolean hasShadow;
5355
protected boolean isOpened;
5456

@@ -83,6 +85,8 @@ public SwitchView(Context context, AttributeSet attrs) {
8385
colorOff = a.getColor(R.styleable.SwitchView_offColor, 0xFFE3E3E3);
8486
colorOffDark = a.getColor(R.styleable.SwitchView_offColorDark, 0xFFBFBFBF);
8587
colorShadow = a.getColor(R.styleable.SwitchView_shadowColor, 0xFF333333);
88+
colorBar = a.getColor(R.styleable.SwitchView_barColor, 0xFFFFFFFF);
89+
colorBackground = a.getColor(R.styleable.SwitchView_bgColor, 0xFFFFFFFF);
8690
ratioAspect = a.getFloat(R.styleable.SwitchView_ratioAspect, 0.68f);
8791
hasShadow = a.getBoolean(R.styleable.SwitchView_hasShadow, true);
8892
isOpened = a.getBoolean(R.styleable.SwitchView_isOpened, false);
@@ -123,6 +127,17 @@ public void setColor(int newColorPrimary, int newColorPrimaryDark, int newColorO
123127
invalidate();
124128
}
125129

130+
public void setColor(int newColorPrimary, int newColorPrimaryDark, int newColorOff, int newColorOffDark, int newColorShadow, int newColorBar, int newColorBackground) {
131+
colorPrimary = newColorPrimary;
132+
colorPrimaryDark = newColorPrimaryDark;
133+
colorOff = newColorOff;
134+
colorOffDark = newColorOffDark;
135+
colorShadow = newColorShadow;
136+
colorBar = newColorBar;
137+
colorBackgorund = newColorBackground;
138+
invalidate();
139+
}
140+
126141
public void setShadow(boolean shadow) {
127142
hasShadow = shadow;
128143
invalidate();
@@ -353,7 +368,7 @@ protected void onDraw(Canvas canvas) {
353368
final float scaleOffset = (sRight - sCenterX - bRadius) * (isOn ? 1 - dsAnim : dsAnim);
354369
canvas.save();
355370
canvas.scale(scale, scale, sCenterX + scaleOffset, sCenterY);
356-
paint.setColor(0xFFFFFFFF);
371+
paint.setColor(colorBackground);
357372
canvas.drawPath(sPath, paint);
358373
canvas.restore();
359374
// To prepare center bar path
@@ -372,7 +387,7 @@ protected void onDraw(Canvas canvas) {
372387
// draw bar
373388
canvas.scale(0.98f, 0.98f, bWidth / 2, bWidth / 2);
374389
paint.setStyle(Paint.Style.FILL);
375-
paint.setColor(0xffffffff);
390+
paint.setColor(colorBar);
376391
canvas.drawPath(bPath, paint);
377392
paint.setStyle(Paint.Style.STROKE);
378393
paint.setStrokeWidth(bStrokeWidth * 0.5f);

switchbutton/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<attr name="primaryColorDark" format="color"/>
66
<attr name="offColor" format="color"/>
77
<attr name="offColorDark" format="color"/>
8+
<attr name="barColor" format="color"/>
9+
<attr name="bgColor" format="color"/>
810
<attr name="shadowColor" format="color"/>
911
<attr name="ratioAspect" format="float"/>
1012
<attr name="isOpened" format="boolean"/>

0 commit comments

Comments
 (0)