diff --git a/commons/basic/src/main/ets/utils/ChangeUtil.ets b/commons/basic/src/main/ets/utils/ChangeUtil.ets index fd88d28..b87e1d4 100644 --- a/commons/basic/src/main/ets/utils/ChangeUtil.ets +++ b/commons/basic/src/main/ets/utils/ChangeUtil.ets @@ -181,4 +181,12 @@ export class ChangeUtil { } return length as number; // 已经是数值类型 } + + // 将HEX颜色转换为RGBA格式 + static hexToRgba (hex: string, alpha: number) : string | ResourceStr { + const r = parseInt(hex.slice(1, 3), 16); + const g = parseInt(hex.slice(3, 5), 16); + const b = parseInt(hex.slice(5, 7), 16); + return `rgba(${r}, ${g}, ${b}, ${alpha})`; + }; } \ No newline at end of file