Created
June 26, 2023 11:20
-
-
Save PriyaSindkar/93165fdab63d9211b67631e3b3559532 to your computer and use it in GitHub Desktop.
Default theme for Material 3 in Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val DarkColorScheme = darkColorScheme( | |
primary = Purple80, | |
secondary = PurpleGrey80, | |
tertiary = Pink80 | |
) | |
private val LightColorScheme = lightColorScheme( | |
primary = Purple40, | |
secondary = PurpleGrey40, | |
tertiary = Pink40 | |
/* Other default colors to override | |
background = Color(0xFFFFFBFE), | |
surface = Color(0xFFFFFBFE), | |
onPrimary = Color.White, | |
onSecondary = Color.White, | |
onTertiary = Color.White, | |
onBackground = Color(0xFF1C1B1F), | |
onSurface = Color(0xFF1C1B1F), | |
*/ | |
) | |
// Set of Material typography styles to start with | |
val Typography = Typography( | |
bodyLarge = TextStyle( | |
fontFamily = FontFamily(Font(resId = R.font.rubik_regular)), | |
fontWeight = FontWeight.Normal, | |
fontSize = 16.sp, | |
lineHeight = 24.sp, | |
letterSpacing = 0.5.sp | |
), | |
// Other default text styles to override | |
titleLarge = TextStyle( | |
fontFamily = FontFamily(Font(resId = R.font.rubik_regular)), | |
fontWeight = FontWeight.Normal, | |
fontSize = 22.sp, | |
lineHeight = 28.sp, | |
letterSpacing = 0.sp | |
), | |
labelSmall = TextStyle( | |
fontFamily = FontFamily(Font(resId = R.font.rubik_regular)), | |
fontWeight = FontWeight.Medium, | |
fontSize = 11.sp, | |
lineHeight = 16.sp, | |
letterSpacing = 0.5.sp | |
) | |
) | |
@Composable | |
fun AppTheme( | |
darkTheme: Boolean = isSystemInDarkTheme(), | |
// Dynamic color is available on Android 12+ | |
dynamicColor: Boolean = true, | |
content: @Composable () -> Unit | |
) { | |
val colorScheme = when { | |
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { | |
val context = LocalContext.current | |
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) | |
} | |
darkTheme -> DarkColorScheme | |
else -> LightColorScheme | |
} | |
val view = LocalView.current | |
if (!view.isInEditMode) { | |
SideEffect { | |
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb() | |
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme | |
} | |
} | |
MaterialTheme( | |
colorScheme = colorScheme, | |
typography = Typography, | |
content = content | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment