最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Jetpack Compose add custom themed colors to library - Stack Overflow

programmeradmin5浏览0评论

I develop library with composables. Composables have different foregone colors set for light and dark theme. For example backgroundColor, buttonColor, progressLineColor. I don't want library users to pass any information about theme or colors to composables of library.

What I want is

@Composable
fun SomeLibraryComposable(someText: String) {
    // This color should be different for light/dark modes of consumer app
    val backgroundColor = getThemedBackroundColor()
    ....
}

I see that it is possible to add custom themed palette, using staticCompositionLocalOf, like here. But:

  1. I can't wrap composables in my theme inside library, because I don't know if it's dark or light mode in app. isSystemInDarkMode is appliable only if app uses system dark mode
  2. I should not make library users add staticCompositionLocalOf with my palette to their theme
  3. I should not make library users pass darkMode: Boolean to composables of library to create corresponding theme
发布评论

评论列表(0)

  1. 暂无评论