I'm transitioning from Material Design 2 to Material Design 3 using Java + XML in Android Studio Meerkat Feature Drop | 2024.3.2 Patch 1. I’m building a new app with Theme.Material3.DayNight.NoActionBar
and trying to understand how theme customization works — starting with the status bar, and expanding into other system and theme colors.
The android:statusBarColor
doesn't apply, even when set via XML or overridden in Java. The status bar always matches the background color, not my desired color (e.g., @color/primary_dark
).
<!-- themes.xml -->
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Base.Theme.MaterialDesign3Playground" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorOnPrimary">@color/on_primary</item>
<item name="android:statusBarColor">@color/primary_dark</item>
<item name="android:navigationBarColor" tools:targetApi="l">?attr/colorSurface</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="colorSurface">@color/surface</item>
<item name="android:colorBackground">@color/background</item>
</style>
<style name="Theme.MaterialDesign3Playground" parent="Base.Theme.MaterialDesign3Playground" />
</resources>
And I’ve defined appropriate values in colors.xml
, like primary
, primary_dark
, surface
, and so on.
android:statusBarColor
to a custom color.windowLightStatusBar
.Window window = getWindow();
window.setStatusBarColor(ContextCompat.getColor(this, R.color.primary_dark));
Tried clearing system bar appearance flags to remove LIGHT_STATUS_BAR
.
Also removed EdgeToEdge.enable(this);
and ensured padding using WindowInsetsCompat
.
Yet the status bar always matches the colorBackground
, not statusBarColor
.
Besides the status bar, I’m also unsure about how Material Design 3 handles:
colorPrimary
, colorOnPrimary
— how they're applied across components like Toolbars, FABs, etc.colorSurface
, colorBackground
— and how they interact with window/system colors.Theme.Material3.DayNight
(with ActionBar) is preferable over NoActionBar
if I use MaterialToolbar
.ThemeOverlay.Material3
on components to get proper coloring.I'm okay deferring Jetpack Compose for now. My only focus is Java + XML. I’d love:
A clear way to override the status bar color in MD3.
A beginner-friendly, up-to-date tutorial on how to properly use MD3 theming in XML:
colorPrimary
, colorSurface
, etc.Guidance on using MaterialToolbar
+ ActionBar (with or without NoActionBar
) properly in MD3.
Optional: how to disable Dynamic Colors entirely (already tried skipping DynamicColors.applyToActivities()
).
I’m switching from Material 2 to Material 3, using only Java + XML. I want to deeply understand the theming system — from status bar, navigation bar, surfaces, toolbars, to how color roles behave. I’m stuck with the status bar being unresponsive to overrides, and I’m likely missing newer MD3 changes that aren’t well documented for non-Compose devs.
🙏 If you can point me to:
…it would be a huge help. Thank you!
This problem is due to two reasons:
statusBarColor
with system-computed colors.To fix that
DynamicColors.applyToActivities()
enableEdgeToEdge()
in Main Activity or in the activity you want to show your status bar color <item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>
in your theme and override it in in res/values-v35/styles
(The App Running in Android 15 Emulator with Ststus bar color dark Green)
If you wanna to publish your app in google play console google prefer to enable Edge to Edge feature
If you target Android 16, this line windowOptOutEdgeToEdgeEnforcement
will no longer be available