SuperAPI AI 工具集

cometchat-android-v5-theming

设计与创作

查看项目

更新于 10-15 20:14

技能介绍

用途:该技能用于将 CometChat Android UI Kit v5 的界面主题化,使其配色、字体与整体风格匹配自有应用的设计系统。

主要能力:CometChat 的视觉由 attrs.xml 中定义的 XML 主题属性驱动,所有 CometChat* 组件从当前主题读取这些属性,可在应用主题中覆盖。CometChatTheme 是静态工具类,提供主题颜色的程序化访问并支持运行时覆盖,关键方法包括 setPrimaryColor(int)、getPrimaryColor(Context)、getExtendedPrimaryColor50(Context) 至 getExtendedPrimaryColor900(Context)、getBackgroundColor1(Context)、getTextColorPrimary(Context)、getTextColorSecondary(Context)、getIconTintHighlight(Context)、getIconTintSecondary(Context)。扩展主色 50–900 由主色与白色(浅色模式)或黑色(深色模式)混合自动生成。

使用方式:可在代码中调用 CometChatTheme.setPrimaryColor(Color.parseColor("#6C63FF"))(Java 与 Kotlin 写法相同),但必须在任何 CometChat 组件 inflate 之前调用。也可在 themes.xml 中继承 CometChatTheme.DayNight 并覆盖 cometchatPrimaryColor、cometchatBackgroundColor1/2、cometchatTextColorPrimary/Secondary 等属性。每个组件有对应样式属性,命名规则为 cometchat<ComponentName>Style,例如 cometchatConversationsStyle、cometchatMessageListStyle、cometchatMessageComposerStyle、cometchatMessageHeaderStyle、cometchatUsersStyle、cometchatGroupsStyle、cometchatAvatarStyle、cometchatBadgeStyle、cometchatStatusIndicatorStyle、cometchatMessageReceiptStyle。组件还提供 setBackgroundColor、setTitleTextColor、setTitleTextAppearance、setSeparatorColor、setAvatarStyle、setStatusIndicatorStyle 等 setter 做细调。深色模式遵循 Android DayNight,在 values-night/themes.xml 中定义对应值,CometChatTheme 会自动检测夜间模式并调整扩展色阶。

适用场景:修改 CometChat 颜色以匹配品牌、自定义字体与排版、启用深色模式、应用单组件样式。

限制:全局覆盖应优先使用 XML 主题属性,组件 setter 仅用于微调;扩展主色阶默认自动生成,仅在需要精确品牌色时才手动覆盖;主色必须在组件 inflate 前设置。自定义消息模板请使用 cometchat-android-v5-customization,添加功能请使用 cometchat-android-v5-features。