Skip to content

Instantly share code, notes, and snippets.

@PatilSiddhesh
Last active August 20, 2024 05:27
Show Gist options
  • Save PatilSiddhesh/801613a2a3618f9aa82e1aa1c375953d to your computer and use it in GitHub Desktop.
Save PatilSiddhesh/801613a2a3618f9aa82e1aa1c375953d to your computer and use it in GitHub Desktop.
Material You Theme Sample
package com.siddroid.materialyou.ui.theme
import androidx.compose.ui.graphics.Color
val md_theme_light_primary = Color(0xFF355ca8)
val md_theme_light_onPrimary = Color(0xFFffffff)
val md_theme_light_primaryContainer = Color(0xFFd7e2ff)
val md_theme_light_onPrimaryContainer = Color(0xFF001946)
val md_theme_light_secondary = Color(0xFF006688)
val md_theme_light_onSecondary = Color(0xFFffffff)
val md_theme_light_secondaryContainer = Color(0xFFbee8ff)
val md_theme_light_onSecondaryContainer = Color(0xFF001e2b)
val md_theme_light_tertiary = Color(0xFF1160a4)
val md_theme_light_onTertiary = Color(0xFFffffff)
val md_theme_light_tertiaryContainer = Color(0xFFd2e4ff)
val md_theme_light_onTertiaryContainer = Color(0xFF001c39)
val md_theme_light_error = Color(0xFFB3261E)
val md_theme_light_errorContainer = Color(0xFFF9DEDC)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410E0B)
val md_theme_light_background = Color(0xFFFFFBFE)
val md_theme_light_onBackground = Color(0xFF1C1B1F)
val md_theme_light_surface = Color(0xFFFFFBFE)
val md_theme_light_onSurface = Color(0xFF1C1B1F)
val md_theme_light_surfaceVariant = Color(0xFFE7E0EC)
val md_theme_light_onSurfaceVariant = Color(0xFF49454F)
val md_theme_light_outline = Color(0xFF79747E)
val md_theme_light_inverseOnSurface = Color(0xFFF4EFF4)
val md_theme_light_inverseSurface = Color(0xFF313033)
val md_theme_light_inversePrimary = Color(0xFFadc6ff)
val md_theme_light_shadow = Color(0xFF000000)
val md_theme_dark_primary = Color(0xFFadc6ff)
val md_theme_dark_onPrimary = Color(0xFF002d6f)
val md_theme_dark_primaryContainer = Color(0xFF17448f)
val md_theme_dark_onPrimaryContainer = Color(0xFFd7e2ff)
val md_theme_dark_secondary = Color(0xFF6dd2ff)
val md_theme_dark_onSecondary = Color(0xFF003549)
val md_theme_dark_secondaryContainer = Color(0xFF004d68)
val md_theme_dark_onSecondaryContainer = Color(0xFFbee8ff)
val md_theme_dark_tertiary = Color(0xFF9fc9ff)
val md_theme_dark_onTertiary = Color(0xFF00315c)
val md_theme_dark_tertiaryContainer = Color(0xFF004882)
val md_theme_dark_onTertiaryContainer = Color(0xFFd2e4ff)
val md_theme_dark_error = Color(0xFFF2B8B5)
val md_theme_dark_errorContainer = Color(0xFF8C1D18)
val md_theme_dark_onError = Color(0xFF601410)
val md_theme_dark_onErrorContainer = Color(0xFFF9DEDC)
val md_theme_dark_background = Color(0xFF1C1B1F)
val md_theme_dark_onBackground = Color(0xFFE6E1E5)
val md_theme_dark_surface = Color(0xFF1C1B1F)
val md_theme_dark_onSurface = Color(0xFFE6E1E5)
val md_theme_dark_surfaceVariant = Color(0xFF49454F)
val md_theme_dark_onSurfaceVariant = Color(0xFFCAC4D0)
val md_theme_dark_outline = Color(0xFF938F99)
val md_theme_dark_inverseOnSurface = Color(0xFF1C1B1F)
val md_theme_dark_inverseSurface = Color(0xFFE6E1E5)
val md_theme_dark_inversePrimary = Color(0xFF355ca8)
val md_theme_dark_shadow = Color(0xFF000000)
val seed = Color(0xFF6750A4)
val error = Color(0xFFB3261E)
package com.siddroid.materialyou.ui.theme
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
private val LightThemeColors = lightColorScheme(
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
onPrimaryContainer = md_theme_light_onPrimaryContainer,
secondary = md_theme_light_secondary,
onSecondary = md_theme_light_onSecondary,
secondaryContainer = md_theme_light_secondaryContainer,
onSecondaryContainer = md_theme_light_onSecondaryContainer,
tertiary = md_theme_light_tertiary,
onTertiary = md_theme_light_onTertiary,
tertiaryContainer = md_theme_light_tertiaryContainer,
onTertiaryContainer = md_theme_light_onTertiaryContainer,
error = md_theme_light_error,
errorContainer = md_theme_light_errorContainer,
onError = md_theme_light_onError,
onErrorContainer = md_theme_light_onErrorContainer,
background = md_theme_light_background,
onBackground = md_theme_light_onBackground,
surface = md_theme_light_surface,
onSurface = md_theme_light_onSurface,
surfaceVariant = md_theme_light_surfaceVariant,
onSurfaceVariant = md_theme_light_onSurfaceVariant,
outline = md_theme_light_outline,
inverseOnSurface = md_theme_light_inverseOnSurface,
inverseSurface = md_theme_light_inverseSurface,
inversePrimary = md_theme_light_inversePrimary,
)
private val DarkThemeColors = darkColorScheme(
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
primaryContainer = md_theme_dark_primaryContainer,
onPrimaryContainer = md_theme_dark_onPrimaryContainer,
secondary = md_theme_dark_secondary,
onSecondary = md_theme_dark_onSecondary,
secondaryContainer = md_theme_dark_secondaryContainer,
onSecondaryContainer = md_theme_dark_onSecondaryContainer,
tertiary = md_theme_dark_tertiary,
onTertiary = md_theme_dark_onTertiary,
tertiaryContainer = md_theme_dark_tertiaryContainer,
onTertiaryContainer = md_theme_dark_onTertiaryContainer,
error = md_theme_dark_error,
errorContainer = md_theme_dark_errorContainer,
onError = md_theme_dark_onError,
onErrorContainer = md_theme_dark_onErrorContainer,
background = md_theme_dark_background,
onBackground = md_theme_dark_onBackground,
surface = md_theme_dark_surface,
onSurface = md_theme_dark_onSurface,
surfaceVariant = md_theme_dark_surfaceVariant,
onSurfaceVariant = md_theme_dark_onSurfaceVariant,
outline = md_theme_dark_outline,
inverseOnSurface = md_theme_dark_inverseOnSurface,
inverseSurface = md_theme_dark_inverseSurface,
inversePrimary = md_theme_dark_inversePrimary,
)
@Composable
fun AppTheme(content: @Composable() () -> Unit) {
val inDarkMode: Boolean = isSystemInDarkTheme()
val colors = if (supportsDynamic()) {
val context = LocalContext.current
if (inDarkMode) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (inDarkMode) DarkThemeColors else LightThemeColors
}
MaterialTheme(
colorScheme = colors,
typography = AppTypography,
content = content
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment