We just launched Compose Examples featuring over 150+ components! Check it out →

MaterialTheme

Common

Component in Material 3 Compose

Material Theming refers to the customization of your Material Design app to better reflect your product’s brand.

Material components such as [Button] and [Checkbox] use values provided here when retrieving default values.

All values may be set by providing this component with the [colorScheme][ColorScheme], [typography][Typography] and [shapes][Shapes] attributes. Use this to configure the overall theme of elements within this MaterialTheme.

Any values that are not set will inherit the current value from the theme, falling back to the defaults if there is no parent MaterialTheme. This allows using a MaterialTheme at the top of your application, and then separate MaterialTheme(s) for different screens / parts of your UI, overriding only the parts of the theme definition that need to change.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.material3:material3:1.4.0-alpha02")
}

Overloads

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun MaterialTheme(
    colorScheme: ColorScheme = MaterialTheme.colorScheme,
    shapes: Shapes = MaterialTheme.shapes,
    typography: Typography = MaterialTheme.typography,
    content: @Composable () -> Unit
)

Parameters

namedescription
colorSchemeA complete definition of the Material Color theme for this hierarchy
shapesA set of corner shapes to be used as this hierarchy's shape system
typographyA set of text styles to be used as this hierarchy's typography system
contentThe content inheriting this theme
@ExperimentalMaterial3ExpressiveApi
@Composable
fun MaterialTheme(
    colorScheme: ColorScheme = MaterialTheme.colorScheme,
    motionScheme: MotionScheme = MaterialTheme.motionScheme,
    shapes: Shapes = MaterialTheme.shapes,
    typography: Typography = MaterialTheme.typography,
    content: @Composable () -> Unit
)

Parameters

namedescription
colorSchemeA complete definition of the Material Color theme for this hierarchy
motionSchemeA complete definition of the Material Motion scheme for this hierarchy
shapesA set of corner shapes to be used as this hierarchy's shape system
typographyA set of text styles to be used as this hierarchy's typography system

Code Example

MaterialThemeSample

@Preview
@Composable
fun MaterialThemeSample() {

    val isDarkTheme = isSystemInDarkTheme()
    val supportsDynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S

    val lightColorScheme = lightColorScheme(primary = Color(0xFF1EB980))

    val darkColorScheme = darkColorScheme(primary = Color(0xFF66ffc7))

    val colorScheme =
        when {
            supportsDynamicColor && isDarkTheme -> {
                dynamicDarkColorScheme(LocalContext.current)
            }
            supportsDynamicColor && !isDarkTheme -> {
                dynamicLightColorScheme(LocalContext.current)
            }
            isDarkTheme -> darkColorScheme
            else -> lightColorScheme
        }

    val typography =
        Typography(
            displaySmall = TextStyle(fontWeight = FontWeight.W100, fontSize = 96.sp),
            labelLarge = TextStyle(fontWeight = FontWeight.W600, fontSize = 14.sp)
        )

    val shapes = Shapes(extraSmall = RoundedCornerShape(3.0.dp), small = RoundedCornerShape(6.0.dp))

    MaterialTheme(colorScheme = colorScheme, typography = typography, shapes = shapes) {
        val currentTheme = if (!isSystemInDarkTheme()) "light" else "dark"
        ExtendedFloatingActionButton(
            text = { Text("FAB with text style and color from $currentTheme theme") },
            icon = { Icon(Icons.Filled.Favorite, contentDescription = "Localized Description") },
            onClick = {}
        )
    }
}
by @alexstyl