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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> 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
}
}
</code>
<code> 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 } } </code>
    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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> LaunchedEffect(type) {
if (type == DEFAULT) {
window.statusBarColor = Color.TRANSPARENT
wic.isAppearanceLightStatusBars = false
}
else {
window.statusBarColor = Color.WHITE
wic.isAppearanceLightStatusBars = true
}
</code>
<code> LaunchedEffect(type) { if (type == DEFAULT) { window.statusBarColor = Color.TRANSPARENT wic.isAppearanceLightStatusBars = false } else { window.statusBarColor = Color.WHITE wic.isAppearanceLightStatusBars = true } </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

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??

1

To change the color of the status bar icons and text (including the clock) in Jetpack Compose using Kotlin, you can use the WindowInsetsController function to set the color of the status bar icons and text. In Jetpack Compose, access to some system settings (such as the status bar) must be done via activity.

Here’s a sample code to change the color of the status bar icons and text to white:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> // Set the status bar icon color to white
WindowCompat.setDecorFitsSystemWindows(window, false)
val controller = WindowInsetsControllerCompat(window, window.decorView)
controller.isAppearanceLightStatusBars = false // false for white icons, true for dark icons
</code>
<code> // Set the status bar icon color to white WindowCompat.setDecorFitsSystemWindows(window, false) val controller = WindowInsetsControllerCompat(window, window.decorView) controller.isAppearanceLightStatusBars = false // false for white icons, true for dark icons </code>
 // Set the status bar icon color to white
    WindowCompat.setDecorFitsSystemWindows(window, false)
    val controller = WindowInsetsControllerCompat(window, window.decorView)
    controller.isAppearanceLightStatusBars = false // false for white icons, true for dark icons

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật