fix a crash issue,all colorstatelist must be used as deep copy

This commit is contained in:
houzh 2023-11-27 09:05:40 +08:00
parent 6f0bab1e6e
commit 824f89c661

View File

@ -47,7 +47,7 @@ Switch::Switch(Context* context,const AttributeSet& a)
ColorStateList* trackTintList = context->getColorStateList("trackTint");
if (trackTintList) {
mTrackTintList = trackTintList;
mTrackTintList = new ColorStateList(*trackTintList);
mHasTrackTint = true;
}
/*BlendMode trackTintMode = Drawable.parseBlendMode(a.getInt(com.android.internal.R.styleable.Switch_trackTintMode, -1), null);
@ -233,7 +233,10 @@ Drawable* Switch::getTrackDrawable() {
}
void Switch::setTrackTintList(ColorStateList* tint){
mTrackTintList = tint;
delete mTrackTintList;
mTrackTintList = nullptr;
if(tint)
mTrackTintList = new ColorStateList(*tint);
mHasTrackTint = true;
applyTrackTint();
}