You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

状态栏设为白色后图标不可见,如何修改状态栏图标颜色?

Fixing Status Bar Icon Color After Setting White Status Bar

Hey there! I totally get this frustration—setting a white status bar makes those default light icons disappear into the background. Let’s break this down by platform since Android and iOS handle status bar styling differently.

Android Solutions

For Traditional View-Based Apps

You need to tell the system to use dark icons against your white status bar. Here are two reliable ways:

  1. Update your app theme (recommended)
    Open your res/values/styles.xml (or styles-v23.xml for API 23+) and add these attributes to your app theme:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- For API 23+ -->
        <item name="android:statusBarColor">@android:color/white</item>
        <item name="android:windowLightStatusBar">true</item>
    </style>
    

    The windowLightStatusBar flag tells Android to render dark status bar icons (battery, signal, time) when the status bar is light-colored.

  2. Set it programmatically in your Activity
    If you need to toggle this dynamically, use WindowInsetsControllerCompat (works across API levels):

    import androidx.core.view.WindowInsetsControllerCompat
    
    // Inside your Activity's onCreate method
    val window = window
    WindowInsetsControllerCompat(window, window.decorView).apply {
        isAppearanceLightStatusBars = true // Enables dark icons
        window.statusBarColor = android.graphics.Color.WHITE
    }
    

    For older APIs (below 23), you can use the deprecated systemUiVisibility flag:

    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
    window.statusBarColor = android.graphics.Color.WHITE
    

For Jetpack Compose Apps

Use the SystemUiController from the accompanist library to handle this easily:

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@Composable
fun MyAppContent() {
    val systemUiController = rememberSystemUiController()
    
    // Set status bar to white and enable dark icons
    systemUiController.setStatusBarColor(
        color = android.graphics.Color.WHITE,
        darkIcons = true
    )

    Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
        // Your app content here
    }
}

Note: You’ll need to add the accompanist dependency to your build.gradle if you haven’t already.

iOS Solutions

For iOS 13+

You can set the status bar style directly in your UIViewController:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .darkContent // Uses dark icons for light status bar
}

If you want this to apply globally, update your Info.plist:

  1. Add the key UIViewControllerBasedStatusBarAppearance and set it to NO
  2. Add UIStatusBarStyle and set its value to UIStatusBarStyleDarkContent

For Older iOS Versions (iOS 12 and below)

Use .default for dark icons (since .darkContent doesn’t exist pre-iOS 13):

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .default
}

And update the Info.plist key UIStatusBarStyle to UIStatusBarStyleDefault if setting globally.

That should get those status bar icons visible again against your white status bar! Let me know if you hit any snags with specific versions or edge cases.

内容的提问来源于stack exchange,提问作者being_sohelkhan

火山引擎 最新活动