Skip to content

toolbar text color doesn't change, for example, you can enable a black theme in the system and a white one in the application #5

Description

@ishumakov881

@composable
fun SetSystemBarColors(isDarkTheme: Boolean) {//Actual android
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDarkTheme
WindowCompat.getInsetsController(window, view).isAppearanceLightNavigationBars = !isDarkTheme
}
}
}

@composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = false, //true

preferHelper: PreferenceHelper = rememberPreferenceHelper(),
darkColorScheme: ColorScheme = darkColorScheme(),
lightColorScheme: ColorScheme = lightColorScheme(),
content: @Composable PreferableMaterialTheme.() -> Unit

) {
//... dynamic theme ...
// val colorScheme = when {
// dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
// val context = LocalContext.current
// if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
// }
//
// darkTheme -> DarkColorScheme
// else -> LightColorScheme
// }

SetSystemBarColors(darkTheme)//Toolbar Fix

val themePrefs = rememberThemePrefs(preferHelper, darkColorScheme, lightColorScheme, /*Here you need to add a flag to use a dynamic theme*/)

CompositionLocalProvider(
    LocalThemePrefs provides themePrefs,
) {
    MaterialTheme(
        colorScheme = themePrefs.colorScheme,
        content = { PreferableMaterialTheme.content() }
    )
}

}

Activity

  1. changed the title [-]Bro, the toolbar text color doesn't change, for example, you can enable a black theme in the system and a white one in the application[/-] [+]toolbar text color doesn't change, for example, you can enable a black theme in the system and a white one in the application[/+] on Dec 25, 2025
  2. softartdev commented on Dec 26, 2025

    @softartdev
    Owner

    Here is how system bar (status and navigation bar) color handling is currently implemented in MaterialThemePrefs, taking the actual sample setup into account.

    Material Design 3

    System bar color switching is supported and intentionally implemented for Material Design 3.

    In the sample module, edge-to-edge configuration is centralized in the Android helper EdgeToEdge.android.kt, which is used by both themes. However, only the Material Design 3 theme is able to fully and consistently reflect system bar appearance changes, as it integrates correctly with edge-to-edge, window insets, and modern system UI behavior.

    With this setup, system bar icon and background colors remain in sync with the application theme across supported Android API levels.

    Material Design 2

    For Material Design 2, reliable dynamic switching of system bar colors is not achievable, even though the same EnableEdgeToEdge helper is used in the sample. This is due to a combination of:

    • limitations of the Material Design 2 library,
    • Android SDK behavior differences across API levels,
    • unstable and inconsistent results when combining window insets, system UI flags, and legacy theming.

    Because of these constraints, the library deliberately falls back to a standard system status bar for light and dark themes when Material Design 2 theme is selected.

    The workaround proposed in this issue (manual usage of WindowInsetsController and isAppearanceLightStatusBars) is a known approach, but in practice it also behaves poorly with Material Design 2 (see the attached screenshot).
    Image
    If this behavior is acceptable, it can be applied at the application level alongside MaterialThemePrefs. The library modules themselves are designed not to introduce side effects in this scenario.

    Contributions

    If a solution is found that:

    • works correctly for both Material Design 2 and Material Design 3, and
    • behaves consistently across all Android API levels supported by the library,

    a pull request for the library modules would be appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions