Sergio
Sergio

Reputation: 798

How to change status bar icon´s color in Android?

ANSWER 09/09/24

In Kotlin I have used the following code in my Fragmet to set the status bar color to white or black depending on my necessities:

    override fun onAttach(context: Context) {
    super.onAttach(context)
    if (context is SpotlightInterface) spotlightHelper = context
    mainActivity?.window?.let {
        it.statusBarColor =
            ContextCompat.getColor(context, R.color.color_content_inverse)
        it.navigationBarColor =
            ContextCompat.getColor(context, R.color.color_content_inverse)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            val controller = WindowCompat.getInsetsController(it, it.decorView)
            controller.isAppearanceLightStatusBars = true
            controller.isAppearanceLightNavigationBars = true
        } else
            it.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
    }
}

And if I want to change it from my composable I have used the following code

    LaunchedEffect(type) {

    if (type == DEFAULT) {
        window.statusBarColor = Color.TRANSPARENT
        wic.isAppearanceLightStatusBars = false
    }
    else {
        window.statusBarColor = Color.WHITE
        wic.isAppearanceLightStatusBars = true
    }

OLD QUESTION

I am creating a new screen using the enableEdgeToEdge() function. On this screen, an image gallery is shown under the status bar. Depending on the pictures that I receive from the API, sometimes the icons of the status bar are not completely visible as you can see in the left part of the screenshot

enter image description here

The time is not visible.

I am trying to find a way to set this text or this icon's color to another one, or at least change that text and icons to white.

I have seen that you can customize the status bar scrim but this is not a good solution for me, because I will be hiding part of the image and also the text keeps black.

Is there any way to modify this without changing the app theme or using excessively tricky methods??

Upvotes: 1

Views: 318

Answers (0)

Related Questions