You are currently viewing Theming in Android 9 vs 11

Theming in Android 9 vs 11

I am testing my applications on an Android 9 and 11 phone. I’ve noticed that they read my theme.xml file differently. Specifically, Android 9 seems to format the action bar using colorSurface and Android 11 uses colorPrimary. There is other little things happening in other places for me as well. Is there a place in the Kotlin documentation where I can see best practices for theming between Android versions?

Here is my theme.xml for some context.

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryVariant">@color/magenta</item>
<item name="colorOnPrimary">@color/yellow</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/green</item>
<item name="colorSecondaryVariant">@color/magenta</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">@color/blue</item>
<!-- Text Fields -->
<item name="android:textColor">@color/yellow</item>
<item name="android:textColorHint">@color/gray</item>
<!-- Background color -->
<item name="android:windowBackground">@color/black_theme</item>
<!-- sets action bar color -->
<item name="colorSurface">@color/black_theme</item>
</style>
<style name="AppTheme.Login" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- disables action bar -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--colors-->
<item name="android:statusBarColor" tools:targetApi="l">@color/blue</item>
<item name="colorPrimary">@color/blue</item>
<item name="android:textColor">@color/yellow</item>
<item name="android:textColorHint">@color/gray</item>
<item name="android:windowBackground">@color/black_theme</item>
</style>
<style name="AppTheme.Main">
<!-- Can change main theme here-->
</style>
</resources>

submitted by /u/CoffeeBlack7
[link] [comments]