NowUIColoring を使用してテーマ NowWebTheme と NowChatTheme を使用
NowUIColoring インターフェイスには、すべての NowSDK モジュールで使用されるすべての色が含まれています。
複数の SDK モジュール間で同様の色変数を使用するシナリオでは、 NowUIColoring インターフェイスを実装できます。このインターフェイスを使用すると、色の値を上書きし、その実装を使用して、テーマクラス NowWebTheme および NowChatTheme 内の nowUIColoring 値を上書きできます。色変数が上書きされない場合、 NowUIColoring インターフェイスはデフォルトの色を使用します。
次のコード例は、Web UI とチャット UI の両方の色をオーバーライドする方法を示しています。
// Implement the NowUIColoring and override desired color variables
val nowUIColoringImpl = object : NowUIColoring {
override val brand: Int
get() = Color.BLUE
override val textPrimary: Int
get() = Color.WHITE
//override the rest of color variables
}
// Override the nowUIColoring for NowWeb value using the NowUIColoring implementation
lifecycleScope.launch {
sdkManager.getNowWebService()?.launch(activity, URL("https://instance-name.service-now.com"), object : NowWebTheme {
override val nowUIColoring: NowUIColoring
get() = nowUIColoringImpl
})
}
//Override the nowUIColoring for NowChat value using the NowUIColoring implementation
lifecycleScope.launch {
sdkManager.getNowChatService()?.start(activity, object : NowChatTheme {
override val nowUIColoring: NowUIColoring
get() = nowUIColoringImpl
})
}
ダークテーマのサポート
NowChat でダークテーマをサポートするには、NowChatTheme の独自のダークテーマ実装を提供し、 それを NowChatService.start() 関数と NowChatService.updateTheme() 関数で使用します。または、デフォルトのダークテーマカラーで NowChatTheme インターフェイスを実装する NowChatThemeDark クラスを使用することもできます。このクラスは、カスタムダークテーマ実装のベースとして使用することもできます。
val chatService = serviceManager.getNowChatService()
val chatThemeLight = object : NowChatTheme {
override val backgroundPrimary: Int
get() = Color.WHITE
override val textPrimary: Int
get() = Color.BLACK
// Override remaining theme colors
}
//create dark theme using the NowChatThemeDark class
val chatThemeDark = object : NowChatThemeDark(){
override val backgroundPrimary: Int
get() = Color.BLACK
override val textPrimary: Int
get() = Color.WHITE
// Override remaining theme colors
}
//start NowChat with light theme
chatService?.start(activity, chatThemeLight)
//update NowChat theme to dark theme
chatService?.updateTheme(chatThemeDark)