AppCompatTheme

@Composable()
fun AppCompatTheme(context: Context = LocalContext.current, readColors: Boolean = true, readTypography: Boolean = true, shapes: Shapes = MaterialTheme.shapes, content: @Composable() () -> Unit)

This function creates the components of a MaterialTheme, synthesizing a material theme from values in the context's Theme.AppCompat theme.

If you are using Material Design Components in your app, you should use the MDC Compose Theme Adapter instead, as it allows much finer-grained reading of your theme.

Synthesizing a material theme from an AppCompat theme is not perfect, since Theme.AppCompat does not expose the same level of customization as Theme.MaterialComponents. Going through the pillars of material theming:

Colors

AppCompat has a limited set of top-level color attributes, which means that AppCompatTheme has to generate/select alternative colors in certain situations. The mapping is currently:

primarycolorPrimary
primaryVariantcolorPrimaryDark
onPrimaryCalculated black/white
secondarycolorAccent
secondaryVariantcolorAccent
onSecondaryCalculated black/white
surfaceDefault
onSurfaceandroid:textColorPrimary, else calculated black/white
backgroundandroid:colorBackground
onBackgroundandroid:textColorPrimary, else calculated black/white
errorcolorError
onErrorCalculated black/white

Where the table says "calculated black/white", this means either black/white, depending on which provides the greatest contrast against the corresponding background color.

Typography

AppCompat does not provide any semantic text appearances (such as headline6, body1, etc), and instead relies on text appearances for specific widgets or use cases. As such, the only thing we read from an AppCompat theme is the default app:fontFamily or android:fontFamily. For example:

<style name="Theme.MyApp" parent="Theme.AppCompat">
<item name="fontFamily">@font/my_font</item>
</style>

Compose does not currently support downloadable fonts, so any font referenced from the theme should from your resources. See here for more information.

Shape

AppCompat has no concept of shape theming, therefore we use the default value from MaterialTheme.shapes. If you wish to provide custom values, use the shapes parameter.

Parameters

context

The context to read the theme from.

readColors

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

readTypography

whether to read the font family from context's theme.

shapes

A set of shapes to be used by the components in this hierarchy.