From efe99f2a5a2334a4ccb7d7233e2e8a906d517097 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 3 Oct 2021 17:27:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/lib/theme/TintHelper.kt | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index ee18d6aa5..d1bfd0231 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -67,9 +67,10 @@ object TintHelper { when (view) { is Button -> { sl = getDisabledColorStateList(color, disabled) - val rd = view.getBackground() as RippleDrawable - rd.setColor(ColorStateList.valueOf(rippleColor)) - + if (view.getBackground() is RippleDrawable) { + val rd = view.getBackground() as RippleDrawable + rd.setColor(ColorStateList.valueOf(rippleColor)) + } // Disabled text color state for buttons, may get overridden later by ATE tags view.setTextColor( getDisabledColorStateList( @@ -164,23 +165,24 @@ object TintHelper { } else -> isBg = true } - - // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) - val rd = view.background as RippleDrawable - @SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor( - view.context, - if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light - ) - val checked = ColorUtils.adjustAlpha(color, 0.4f) - val sl = ColorStateList( - arrayOf( - intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked), - intArrayOf(android.R.attr.state_activated), - intArrayOf(android.R.attr.state_checked) - ), - intArrayOf(unchecked, checked, checked) - ) - rd.setColor(sl) + if (!isBg && view.background is RippleDrawable) { + // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) + val rd = view.background as RippleDrawable + @SuppressLint("PrivateResource") val unchecked = ContextCompat.getColor( + view.context, + if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light + ) + val checked = ColorUtils.adjustAlpha(color, 0.4f) + val sl = ColorStateList( + arrayOf( + intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked), + intArrayOf(android.R.attr.state_activated), + intArrayOf(android.R.attr.state_checked) + ), + intArrayOf(unchecked, checked, checked) + ) + rd.setColor(sl) + } } if (isBg) { // Need to tint the isBackground of a view