用途:在 Kotlin Views 中应用和自定义 CometChat 主题,涵盖 XML 主题属性、通过 CometChatTheme 单例进行颜色/字体程序化覆盖、深色模式支持以及各组件样式类。
主要能力:CometChatTheme 是 com.cometchat.uikit.kotlin.theme 中的 Kotlin object,提供基于 Context 的 getter/setter 访问全部主题令牌。可设置主色、错误色,获取文本色等。支持在 styles.xml/themes.xml 中声明 cometchatPrimaryColor、cometchatNeutralColor50-900、cometchatSuccessColor/ErrorColor/WarningColor/InfoColor/MessageReadColor、背景色 cometchatBackgroundColor1-4、描边色、文本色、图标着色及按钮颜色等属性。扩展主色可在未显式设置时由主色与白色(日间)或黑色(夜间)混合自动生成。排版方面提供 Title、Heading1-4、Body、Caption1-2、Button、Link 与 Regular/Medium/Bold 组合的 text appearance 资源 ID,以及 getFontRegular/Medium/Bold 字体资源 ID,可通过 XML 属性覆盖。
深色模式:通过 Configuration.UI_MODE_NIGHT_MASK 检测,自动使用 day/night 限定资源并按模式混合颜色;程序化覆盖需在检测模式后设置。
使用方式与限制:getter 必须传入有效 Context,因需从主题解析 XML 属性;程序化 setter 优先级高于 XML;程序化覆盖会缓存在内存,主题变化时需调用 CometChatTheme.clearCache();仅在需要特定色阶时才覆盖自动生成的扩展主色。不要将 Compose 的 CometChatTheme.colorScheme 与 Views 的 CometChatTheme.getPrimaryColor(ctx) 混用,二者是不同模块中的独立主题系统。Compose 主题请用 cometchat-android-v6-compose-theming,气泡渲染定制请用 cometchat-android-v6-kotlin-customization。