序列化不透明的 Color 时省略 Alpha 通道的值 (#4415)

This commit is contained in:
Glavo 2025-09-09 20:21:18 +08:00 committed by GitHub
parent 480f8b6890
commit 37ad445620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,7 +40,10 @@ public final class PaintAdapter extends TypeAdapter<Paint> {
int green = (int) Math.round(color.getGreen() * 255.);
int blue = (int) Math.round(color.getBlue() * 255.);
int opacity = (int) Math.round(color.getOpacity() * 255.);
out.value(String.format("#%02x%02x%02x%02x", red, green, blue, opacity));
if (opacity < 255)
out.value(String.format("#%02x%02x%02x%02x", red, green, blue, opacity));
else
out.value(String.format("#%02x%02x%02x", red, green, blue));
} else if (value instanceof LinearGradient
|| value instanceof RadialGradient) {
out.value(value.toString());