Colton Idle

    Colton Idle

    1 year ago
    Is there any guide on how to define colors for my app if we're not following Material theme?
    Yashar

    Yashar

    1 year ago
    You can define your own theme(s). Here is a helpful video to get started:

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

    Colton Idle

    Colton Idle

    1 year ago
    I've seen that, but it looks like it's just extending material theme/colors.
    f

    fmasa

    1 year ago
    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:
    @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
    }