https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

02/03/2021, 3:24 PM
Is there any guide on how to define colors for my app if we're not following Material theme?
y

Yashar

02/03/2021, 3:46 PM
You can define your own theme(s). Here is a helpful video to get started:

https://www.youtube.com/watch?v=oE4iCfS6Gso&t=2s

c

Colton Idle

02/03/2021, 3:49 PM
I've seen that, but it looks like it's just extending material theme/colors.
f

fmasa

02/03/2021, 4:36 PM
You can roll your own ambient (if you need different themes) or define static values somewhere - MaterialTheme object + MaterialTheme composable is good example. So something like this (very barebones) example should do the job:
Copy code
@Immutable
data class AppColors(
    val colorOne: Color,
    val colorTwo: Color,
)

fun defaultColors() = AppColors(Color.RED, Color.BLACK)

val AmbientAppColors = staticAmbientOf { defaultColors() }

object AppTheme {
    val colors: AppColors
        @Composable
        @ComposableContract(readonly = true)
        get() = AmbientAppColors.current
}

// Then in your code
Text("Foo", color = AppTheme.colors.colorOne)

// Overriding theme (where darkColors returns instance of AppColors
Provides (AmbientAppColors provides darkColors()) {
// UI using dark theme
}