@@ -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 );
0 commit comments