From 40cb04dfab6aa03814ff7c2306288429572ebe0b Mon Sep 17 00:00:00 2001 From: HapeLee <63206378+HapeLee@users.noreply.github.com> Date: Mon, 8 Jun 2026 00:27:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20BgTextConfigSheet?= =?UTF-8?q?=20=E4=B8=AD=20Color.parseColor=20=E5=B4=A9=E6=BA=83=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 bgStr/bgStrNight 为空字符串或非法颜色值时,toColorInt() 会抛出 IllegalArgumentException: Unknown color。使用 runCatching 包裹并提供 合理的默认值(日间 #EEEEEE,夜间 #000000)。 --- .../io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt b/app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt index c901b1d4d..103c5f849 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt @@ -62,8 +62,12 @@ fun BgTextConfigSheet( val styleName = styleConfig.styleName val darkStatusIcon = styleConfig.darkStatusIcon val bgAlpha = styleConfig.bgAlpha - val dayBgColor = if (styleConfig.bgType == 0) styleConfig.bgStr.toColorInt() else 0 - val nightBgColor = if (styleConfig.bgTypeNight == 0) styleConfig.bgStrNight.toColorInt() else 0 + val dayBgColor = if (styleConfig.bgType == 0) { + runCatching { styleConfig.bgStr.toColorInt() }.getOrDefault(0xFFEEEEEE.toInt()) + } else 0 + val nightBgColor = if (styleConfig.bgTypeNight == 0) { + runCatching { styleConfig.bgStrNight.toColorInt() }.getOrDefault(0xFF000000.toInt()) + } else 0 val dayBgImage = if (styleConfig.bgType != 0) styleConfig.bgStr else null val nightBgImage = if (styleConfig.bgTypeNight != 0) styleConfig.bgStrNight else null