|
|
@@ -6,6 +6,7 @@ package kr.co.zumo.app.lifeplus.view.custom;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Rect;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.graphics.drawable.StateListDrawable;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.widget.CompoundButton;
|
|
|
import android.widget.Switch;
|
|
|
@@ -25,19 +26,23 @@ import kr.co.zumo.app.R;
|
|
|
public class OnOffSwitch extends Switch {
|
|
|
|
|
|
protected CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
|
|
|
+ private Context context;
|
|
|
|
|
|
public OnOffSwitch(Context context) {
|
|
|
super(context, null, R.attr.customSwitchStyle);
|
|
|
+ this.context = context;
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
public OnOffSwitch(Context context, AttributeSet attrs) {
|
|
|
super(context, attrs, R.attr.customSwitchStyle);
|
|
|
+ this.context = context;
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
public OnOffSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, R.attr.customSwitchStyle);
|
|
|
+ this.context = context;
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
@@ -45,6 +50,11 @@ public class OnOffSwitch extends Switch {
|
|
|
Rect paddingRect = new Rect(getPaddingStart(), getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
|
|
setTrackDrawable(new SwitchTrackTextDrawable(getContext(), R.string.on, R.string.off, false, paddingRect));
|
|
|
|
|
|
+ StateListDrawable stateListDrawable = new StateListDrawable();
|
|
|
+ stateListDrawable.addState(new int[]{android.R.attr.state_checked}, context.getResources().getDrawable(R.drawable.switch_thumb_on));
|
|
|
+ stateListDrawable.addState(new int[]{-android.R.attr.state_checked}, context.getResources().getDrawable(R.drawable.switch_thumb_off));
|
|
|
+ setThumbDrawable(stateListDrawable);
|
|
|
+
|
|
|
super.setOnCheckedChangeListener((compoundButton, isChecked) -> {
|
|
|
performOnCheckedChanged(compoundButton, isChecked);
|
|
|
|