refactor: 重构调试主题,统一定义应用调试文字颜色

1. 重命名调试主题属性
   - themeGlobalCrashActivity → themeDebug
   - GlobalCrashActivityTheme → DebugActivityTheme

2. 新增 debugTextColor 属性
   - 定义 debugTextColor 属性,用于统一应用调试文字颜色
   - 普通模式: 灰色 #808080
   - 深色模式: 绿色 #FF00FF00

3. 重构视图控件
   - view_globalcrashreport.xml 和 view_log.xml 使用 themeDebug 主题
   - 控件颜色统一引用主题属性
   - 日志显示文本使用 debugTextColor 属性

4. GlobalCrashReportView Java 代码
   - 新增 obtainDebugTextColor() 方法获取主题中的 debugTextColor
   - 崩溃视图文字颜色通过主题属性获取,与日志视图一致
This commit is contained in:
2026-05-11 09:37:25 +08:00
parent 29726828b0
commit a5a5b37121
11 changed files with 93 additions and 69 deletions

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAPPBaseTheme" parent="APPBaseTheme">
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item>
<item name="themeDebug">@style/MyDebugActivityTheme</item>
</style>
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme">
<item name="colorTittle">#FFFFFFFF</item>
<item name="colorTittleBackgound">#FF00A4B3</item>
<item name="colorText">#FFFFFFFF</item>
<item name="colorTextBackgound">#FFFFFFFF</item>
<style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">#FF1E3A5F</item>
<item name="colorText">?attr/mainWindowDarkTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
</style>
</resources>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAPPBaseTheme" parent="APPBaseTheme">
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item>
<item name="themeDebug">@style/MyDebugActivityTheme</item>
</style>
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme">
<item name="colorTittle">#FFFFFFFF</item>
<item name="colorTittleBackgound">#FF00A4B3</item>
<item name="colorText">#FFFFFFFF</item>
<item name="colorTextBackgound">#FF000000</item>
<style name="MyDebugActivityTheme" parent="DebugActivityTheme">
<item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">#FF00B322</item>
<item name="colorText">?attr/mainWindowTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
</style>
</resources>

View File

@@ -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&豆包大模型<zhangsken@qq.com>
@@ -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

View File

@@ -2,7 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="?attr/themeGlobalCrashActivity"
android:theme="?attr/themeDebug"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="?attr/themeDebug"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor">
android:background="?attr/colorTextBackgound">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_alignParentTop="true"
android:background="?attr/toolbarBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogRelativeLayoutToolbar">
<Button
@@ -19,8 +20,8 @@
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:text="Clean"
android:textColor="?attr/buttonTextColor"
android:backgroundTint="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:backgroundTint="?attr/colorTittleBackgound"
android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/>
@@ -34,8 +35,8 @@
android:layout_toRightOf="@+id/viewlogButtonClean"
android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/buttonTextColor"/>
android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content"
@@ -52,17 +53,17 @@
android:layout_toLeftOf="@+id/viewlogButtonCopy"
android:layout_centerVertical="true"
android:text="Selectable"
android:background="?attr/buttonBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogCheckBoxSelectable"
android:padding="@dimen/log_text_padding"
android:textColor="?attr/buttonTextColor"/>
android:textColor="?attr/colorText"/>
<Button
android:layout_width="@dimen/log_button_width"
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:textColor="?attr/buttonTextColor"
android:backgroundTint="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:backgroundTint="?attr/colorTittleBackgound"
android:text="Copy"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
@@ -78,7 +79,7 @@
android:layout_below="@+id/viewlogRelativeLayoutToolbar"
android:id="@+id/viewlogLinearLayout1"
android:gravity="center_vertical"
android:background="?attr/toolbarBackgroundColor">
android:background="?attr/colorTittleBackgound">
<CheckBox
android:layout_width="wrap_content"
@@ -87,8 +88,8 @@
android:text="ALL"
android:padding="2dp"
android:id="@+id/viewlogCheckBox1"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/buttonTextColor"
android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
@@ -97,15 +98,15 @@
android:ems="10"
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:background="?attr/colorTittleBackgound"
android:singleLine="true"
android:id="@+id/tagsearch_et"/>
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="?attr/buttonBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:scrollbars="none"
android:padding="2dp"
android:layout_weight="1.0"
@@ -131,7 +132,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor"
android:background="?attr/colorTextBackgound"
android:id="@+id/viewlogScrollViewLog">
<TextView
@@ -139,7 +140,7 @@
android:layout_height="match_parent"
android:textSize="@dimen/log_text_size"
android:text="Text"
android:textColor="#FF00FF00"
android:textColor="?attr/debugTextColor"
android:textIsSelectable="true"
android:id="@+id/viewlogTextViewLog"/>

View File

@@ -2,7 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="?attr/themeGlobalCrashActivity"
android:theme="?attr/themeDebug"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="?attr/themeDebug"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor">
android:background="?attr/colorTextBackgound">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_alignParentTop="true"
android:background="?attr/toolbarBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogRelativeLayoutToolbar">
<Button
@@ -19,8 +20,8 @@
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:text="Clean"
android:textColor="?attr/buttonTextColor"
android:backgroundTint="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:backgroundTint="?attr/colorTittleBackgound"
android:layout_centerVertical="true"
android:id="@+id/viewlogButtonClean"
android:layout_marginLeft="5dp"/>
@@ -34,8 +35,8 @@
android:layout_toRightOf="@+id/viewlogButtonClean"
android:layout_centerVertical="true"
android:id="@+id/viewlogTextView1"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/buttonTextColor"/>
android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"/>
<cc.winboll.studio.libappbase.widget.LogTagSpinner
android:layout_width="wrap_content"
@@ -52,17 +53,17 @@
android:layout_toLeftOf="@+id/viewlogButtonCopy"
android:layout_centerVertical="true"
android:text="Selectable"
android:background="?attr/buttonBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:id="@+id/viewlogCheckBoxSelectable"
android:padding="@dimen/log_text_padding"
android:textColor="?attr/buttonTextColor"/>
android:textColor="?attr/colorText"/>
<Button
android:layout_width="@dimen/log_button_width"
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:textColor="?attr/buttonTextColor"
android:backgroundTint="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:backgroundTint="?attr/colorTittleBackgound"
android:text="Copy"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
@@ -78,7 +79,7 @@
android:layout_below="@+id/viewlogRelativeLayoutToolbar"
android:id="@+id/viewlogLinearLayout1"
android:gravity="center_vertical"
android:background="?attr/toolbarBackgroundColor">
android:background="?attr/colorTittleBackgound">
<CheckBox
android:layout_width="wrap_content"
@@ -87,8 +88,8 @@
android:text="ALL"
android:padding="2dp"
android:id="@+id/viewlogCheckBox1"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/buttonTextColor"
android:background="?attr/colorTittleBackgound"
android:textColor="?attr/colorText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
@@ -97,15 +98,15 @@
android:ems="10"
android:layout_height="@dimen/log_button_height"
android:textSize="@dimen/log_text_size"
android:textColor="?attr/activityTextColor"
android:background="?attr/buttonBackgroundColor"
android:textColor="?attr/colorText"
android:background="?attr/colorTittleBackgound"
android:singleLine="true"
android:id="@+id/tagsearch_et"/>
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="?attr/buttonBackgroundColor"
android:background="?attr/colorTittleBackgound"
android:scrollbars="none"
android:padding="2dp"
android:layout_weight="1.0"
@@ -131,7 +132,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activityBackgroundColor"
android:background="?attr/colorTextBackgound"
android:id="@+id/viewlogScrollViewLog">
<TextView
@@ -139,7 +140,7 @@
android:layout_height="match_parent"
android:textSize="@dimen/log_text_size"
android:text="Text"
android:textColor="#FF00FF00"
android:textColor="?attr/debugTextColor"
android:textIsSelectable="true"
android:id="@+id/viewlogTextViewLog"/>

View File

@@ -2,7 +2,7 @@
<resources>
<!-- 全局主题属性 -->
<attr name="themeGlobalCrashActivity" format="reference"/>
<attr name="themeDebug" format="reference"/>
<!-- GlobalCrashActivity 样式属性 -->
<declare-styleable name="GlobalCrashActivity">
@@ -55,4 +55,7 @@
<attr name="mainWindowDarkBackgroundColor" format="color"/>
<attr name="mainWindowDarkTextColor" format="color"/>
<!-- DebugLogStyle 应用调试日志样式属性 -->
<attr name="debugTextColor" format="color"/>
</resources>

View File

@@ -3,7 +3,7 @@
<!-- APPBaseTheme 深色模式主题 -->
<style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item>
<item name="themeDebug">@style/DebugActivityTheme</item>
<item name="aboutViewBackgroundColor">?attr/mainWindowDarkBackgroundColor</item>
<item name="aboutViewTextColor">?attr/mainWindowDarkTextColor</item>
<item name="aboutViewTitleColor">?attr/mainWindowDarkTextColor</item>
@@ -28,12 +28,13 @@
</style>
<!-- GlobalCrashActivityTheme 深色模式样式 -->
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="android:statusBarColor">#FF0D1B2A</item>
<item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittle">?attr/mainWindowDarkTextColor</item>
<item name="colorTittleBackgound">#FF1E3A5F</item>
<item name="colorText">?attr/mainWindowTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
<item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowDarkBackgroundColor</item>
<item name="debugTextColor">#FF00FF00</item>
</style>
<!-- DialogStyle 对话框样式 -->

View File

@@ -2,7 +2,7 @@
<resources>
<!-- 全局主题属性 -->
<attr name="themeGlobalCrashActivity" format="reference"/>
<attr name="themeDebug" format="reference"/>
<!-- AboutView 样式属性 -->
<declare-styleable name="AboutView">
@@ -61,4 +61,7 @@
<attr name="mainWindowDarkBackgroundColor" format="color"/>
<attr name="mainWindowDarkTextColor" format="color"/>
<!-- DebugLogStyle 应用调试日志样式属性 -->
<attr name="debugTextColor" format="color"/>
</resources>

View File

@@ -3,7 +3,7 @@
<!-- APPBaseTheme 普通模式主题 -->
<style name="APPBaseTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item>
<item name="themeDebug">@style/DebugActivityTheme</item>
<item name="aboutViewBackgroundColor">?attr/mainWindowBackgroundColor</item>
<item name="aboutViewTextColor">?attr/mainWindowTextColor</item>
<item name="aboutViewTitleColor">?attr/mainWindowTextColor</item>
@@ -28,12 +28,13 @@
</style>
<!-- GlobalCrashActivityTheme 普通模式样式 -->
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<style name="DebugActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:statusBarColor">#FF00B322</item>
<item name="colorTittle">?attr/mainWindowTextColor</item>
<item name="colorTittleBackgound">#FF00B322</item>
<item name="colorText">?attr/mainWindowTextColor</item>
<item name="colorText">?attr/debugTextColor</item>
<item name="colorTextBackgound">?attr/mainWindowBackgroundColor</item>
<item name="debugTextColor">#FF808080</item>
</style>
<!-- DialogStyle 对话框样式 -->