App Compat Theme
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:
| primary | colorPrimary |
| primaryVariant | colorPrimaryDark |
| onPrimary | Calculated black/white |
| secondary | colorAccent |
| secondaryVariant | colorAccent |
| onSecondary | Calculated black/white |
| surface | Default |
| onSurface | android:textColorPrimary, else calculated black/white |
| background | android:colorBackground |
| onBackground | android:textColorPrimary, else calculated black/white |
| error | colorError |
| onError | Calculated 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.