createMdcTheme

fun createMdcTheme(context: Context, layoutDirection: LayoutDirection, density: Density = Density(context), readColors: Boolean = true, readTypography: Boolean = true, readShapes: Boolean = true, setTextColors: Boolean = false, setDefaultFontFamily: Boolean = false): ThemeParameters

This function creates the components of a androidx.compose.material.MaterialTheme, reading the values from an Material Components for Android theme.

By default the text colors from any associated TextAppearances from the theme are not read. This is because setting a fixed color in the resulting TextStyle breaks the usage of androidx.compose.material.ContentAlpha through androidx.compose.material.LocalContentAlpha. You can customize this through the setTextColors parameter.

For Shapes, the layoutDirection is taken into account when reading corner sizes of ShapeAppearances from the theme. For example, Shapes.medium.topStart will be read from cornerSizeTopLeft for LayoutDirection.Ltr and cornerSizeTopRight for LayoutDirection.Rtl.

The individual components of the returned ThemeParameters may be null, depending on the matching 'read' parameter. For example, if you set readColors to false, ThemeParameters.colors will be null.

Return

ThemeParameters instance containing the resulting Colors, Typography and Shapes.

Parameters

context

The context to read the theme from.

layoutDirection

The layout direction to be used when reading shapes.

density

The current density.

readColors

whether the read the MDC color palette from the context's theme.

readTypography

whether the read the MDC text appearances from context's theme.

readShapes

whether the read the MDC shape appearances from the context's theme.

setTextColors

whether to read the colors from the TextAppearances associated from the theme. Defaults to false.

setDefaultFontFamily

whether to read and prioritize the fontFamily attributes from context's theme, over any specified in the MDC text appearances. Defaults to false.