春节主题:首页弹窗、礼物、部分按钮。
This commit is contained in:
@@ -5,6 +5,9 @@ import android.graphics.Color;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.xscm.moduleutil.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -69,7 +72,7 @@ public class ColorManager {
|
||||
// 解析颜色为int值
|
||||
public int getPrimaryColorInt() {
|
||||
try {
|
||||
return Color.parseColor(primaryColor);
|
||||
return UtilConfig.getAttrColor(ActivityUtils.getTopActivity(), R.attr.app_color_colorPrimary);//Color.parseColor(primaryColor);
|
||||
} catch (Exception e) {
|
||||
return Color.parseColor("#3ABC6D"); // 默认颜色
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.xscm.moduleutil.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.lahm.library.EasyProtectorLib;
|
||||
import com.lahm.library.EmulatorCheckCallback;
|
||||
@@ -50,4 +52,31 @@ public class UtilConfig {
|
||||
public static void setSalt(String salt) {
|
||||
UtilConfig.salt = salt;
|
||||
}
|
||||
|
||||
|
||||
public static int getAttBg(Context context, int attr){
|
||||
// 1. 定义需要获取的自定义属性数组
|
||||
int[] attrs = new int[]{attr};
|
||||
// 2. 从Context的Theme中获取TypedArray(核心:绑定当前主题的属性值)
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||
// 3. 获取attr对应的资源ID,默认值0(无有效资源时返回0)
|
||||
int bgResId = ta.getResourceId(0, 0);
|
||||
// 4. 关键:手动回收TypedArray,释放系统资源,避免内存泄漏
|
||||
ta.recycle();
|
||||
// 5. 有有效资源ID时,设置背景
|
||||
return bgResId;
|
||||
}
|
||||
|
||||
// 新增:解析自定义颜色属性,返回实际颜色码(核心)
|
||||
public static int getAttrColor(Context context, int colorAttrId) {
|
||||
if (context == null) {
|
||||
return Color.BLACK; // 上下文为空时返回默认黑色,可自定义
|
||||
}
|
||||
// 从主题中获取TypedArray,解析颜色属性
|
||||
TypedArray ta = context.obtainStyledAttributes(new int[]{colorAttrId});
|
||||
// getColor(索引, 默认颜色):直接返回十六进制颜色码,适配setTextColor
|
||||
int color = ta.getColor(0, Color.BLACK);
|
||||
ta.recycle(); // 必须回收,避免内存泄漏
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user