这是未经检查的样子:
并检查:
明显不匹配的设计,那么如何使它看起来像未经检查的外观?
最佳答案
您可以为这两个语句使用相同的颜色进行着色:
switchButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
isTouched = true;
switchButton.getThumbDrawable().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_IN);
return false;
}
});
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isTouched) {
isTouched = false;
if (isChecked) {
switchButton.getThumbDrawable().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_IN);
}
else {
switchButton.getThumbDrawable().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_IN);
}
}
}
});