From a5a5b371212623ad586ac3e2266062b09ba2725e Mon Sep 17 00:00:00 2001 From: LaizyBoy Date: Mon, 11 May 2026 09:37:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=B8=BB=E9=A2=98=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=BA=94=E7=94=A8=E8=B0=83=E8=AF=95=E6=96=87=E5=AD=97?= =?UTF-8?q?=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 重命名调试主题属性 - themeGlobalCrashActivity → themeDebug - GlobalCrashActivityTheme → DebugActivityTheme 2. 新增 debugTextColor 属性 - 定义 debugTextColor 属性,用于统一应用调试文字颜色 - 普通模式: 灰色 #808080 - 深色模式: 绿色 #FF00FF00 3. 重构视图控件 - view_globalcrashreport.xml 和 view_log.xml 使用 themeDebug 主题 - 控件颜色统一引用主题属性 - 日志显示文本使用 debugTextColor 属性 4. GlobalCrashReportView Java 代码 - 新增 obtainDebugTextColor() 方法获取主题中的 debugTextColor - 崩溃视图文字颜色通过主题属性获取,与日志视图一致 --- appbase/src/main/res/values-night/styles.xml | 12 +++--- appbase/src/main/res/values/styles.xml | 12 +++--- .../libappbase/GlobalCrashReportView.java | 32 +++++++++++----- .../layout-night/view_globalcrashreport.xml | 2 +- .../src/main/res/layout-night/view_log.xml | 37 ++++++++++--------- .../res/layout/view_globalcrashreport.xml | 2 +- libappbase/src/main/res/layout/view_log.xml | 37 ++++++++++--------- .../src/main/res/values-night/attrs.xml | 5 ++- .../src/main/res/values-night/styles.xml | 11 +++--- libappbase/src/main/res/values/attrs.xml | 5 ++- libappbase/src/main/res/values/styles.xml | 7 ++-- 11 files changed, 93 insertions(+), 69 deletions(-) diff --git a/appbase/src/main/res/values-night/styles.xml b/appbase/src/main/res/values-night/styles.xml index 4d0fa5f..40600c3 100644 --- a/appbase/src/main/res/values-night/styles.xml +++ b/appbase/src/main/res/values-night/styles.xml @@ -1,13 +1,13 @@ - \ No newline at end of file diff --git a/appbase/src/main/res/values/styles.xml b/appbase/src/main/res/values/styles.xml index bfb751e..4417b69 100644 --- a/appbase/src/main/res/values/styles.xml +++ b/appbase/src/main/res/values/styles.xml @@ -1,13 +1,13 @@ - diff --git a/libappbase/src/main/java/cc/winboll/studio/libappbase/GlobalCrashReportView.java b/libappbase/src/main/java/cc/winboll/studio/libappbase/GlobalCrashReportView.java index 43a0891..7ecedcc 100644 --- a/libappbase/src/main/java/cc/winboll/studio/libappbase/GlobalCrashReportView.java +++ b/libappbase/src/main/java/cc/winboll/studio/libappbase/GlobalCrashReportView.java @@ -12,6 +12,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toolbar; import cc.winboll.studio.libappbase.R; +import android.content.res.Resources; /** * @Author ZhanGSKen&豆包大模型 @@ -175,10 +176,11 @@ public class GlobalCrashReportView extends LinearLayout { * 初始化默认配置(无自定义属性时使用) */ private void initDefaultConfig() { - // 设置默认配色(普通模式黑色文字) - mTitleColor = Color.BLACK; - mTitleBackgroundColor = Color.BLACK; - mTextColor = Color.BLACK; + // 设置默认配色(使用 debugTextColor 属性) + Resources.Theme theme = mContext.getTheme(); + mTitleColor = theme.getResources().getColor(android.R.color.holo_green_dark); + mTitleBackgroundColor = Color.GRAY; + mTextColor = obtainDebugTextColor(theme); mTextBackgroundColor = Color.WHITE; // 加载布局 inflateView(); @@ -186,6 +188,21 @@ public class GlobalCrashReportView extends LinearLayout { initWidgetStyle(); } + private int obtainDebugTextColor(Resources.Theme theme) { + int[] attrs = new int[] { cc.winboll.studio.libappbase.R.attr.themeDebug }; + TypedArray themeTypedArray = theme.obtainStyledAttributes(attrs); + int themeResId = themeTypedArray.getResourceId(0, 0); + themeTypedArray.recycle(); + if (themeResId != 0) { + int[] debugAttrs = new int[] { cc.winboll.studio.libappbase.R.attr.debugTextColor }; + TypedArray debugTypedArray = theme.obtainStyledAttributes(themeResId, debugAttrs); + int color = debugTypedArray.getColor(0, Color.GRAY); + debugTypedArray.recycle(); + return color; + } + return Color.GRAY; + } + /** * 初始化视图(解析自定义属性 + 加载布局 + 设置样式) * @param attrs 自定义属性集合 @@ -195,7 +212,7 @@ public class GlobalCrashReportView extends LinearLayout { TypedArray typedArray = mContext.obtainStyledAttributes( attrs, R.styleable.GlobalCrashActivity, - R.attr.themeGlobalCrashActivity, + R.attr.themeDebug, 0 ); @@ -208,10 +225,7 @@ public class GlobalCrashReportView extends LinearLayout { R.styleable.GlobalCrashActivity_colorTittleBackgound, // 注:原拼写错误(Backgound→Background),保持与 attrs.xml 一致 Color.BLACK ); - mTextColor = typedArray.getColor( - R.styleable.GlobalCrashActivity_colorText, - Color.BLACK - ); + mTextColor = obtainDebugTextColor(mContext.getTheme()); mTextBackgroundColor = typedArray.getColor( R.styleable.GlobalCrashActivity_colorTextBackgound, // 注:原拼写错误,保持与 attrs.xml 一致 Color.WHITE diff --git a/libappbase/src/main/res/layout-night/view_globalcrashreport.xml b/libappbase/src/main/res/layout-night/view_globalcrashreport.xml index 2df3e47..a5f427e 100644 --- a/libappbase/src/main/res/layout-night/view_globalcrashreport.xml +++ b/libappbase/src/main/res/layout-night/view_globalcrashreport.xml @@ -2,7 +2,7 @@ + android:background="?attr/colorTextBackgound">