//动态设置switch的颜色
imgOpenSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
int thumbColor;
int trackColor;
if(isChecked) {
thumbColor = theme;
trackColor = thumbColor;
} else {
thumbColor = Color.argb(255, 236, 236, 236);
trackColor = Color.argb(255, 0, 0, 0);
}
try {
imgOpenSwitch.getThumbDrawable().setColorFilter(new PorterDuffColorFilter(thumbColor,PorterDuff.Mode.MULTIPLY));
imgOpenSwitch.getTrackDrawable().setColorFilter(new PorterDuffColorFilter(trackColor, PorterDuff.Mode.MULTIPLY));
}
catch (NullPointerException e) {
e.printStackTrace();
}
});
上一篇
动态修改seekbar颜色
2020-03-26
下一篇
安卓保存内容到内置存储
2020-03-26