Home » Android » Is there a way to change the Android status bar color with React Native?

Is there a way to change the Android status bar color with React Native?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I just got started with React Native for Android, and I’m trying to figure out if there’s a way to change the status bar color for Android…

Like this?

enter image description here

How to&Answers:

I’ve made an npm package to control the StatusBar in android

https://www.npmjs.com/package/react-native-android-statusbar

The color changes do not reflect for versions before 21

Answer:

You can use React Native Status Bar(detailed description here). All you need to do is wrapping navigator with a view and adding a StatusBar component above it. Don’t forget to import StatusBar from ‘react-native’ package.

<View>
  <StatusBar
    backgroundColor="blue"
    barStyle="light-content"
  />
  <Navigator
    initialRoute={{statusBarHidden: true}}
    renderScene={(route, navigator) =>
      <View>
        <StatusBar hidden={route.statusBarHidden} />
         ...
      </View>
    }
  />
</View>

One thing I’ve noticed is that you should style the parent View with flex:1, without it you’ll just see a white blank screen. It’s not mentioned in RN Documents though.

Answer:

Yes you can:

import {StatusBar} from 'react-native';

componentDidMount() {
  StatusBar.setBarStyle( 'light-content',true)
  StatusBar.setBackgroundColor("#0996AE")
}

Answer:

You can use react-native in-build StatusBar function

import {StatusBar} from 'react-native';

render() {

        return <View>
            <StatusBar
                backgroundColor="#264d9b"
                barStyle="light-content"
            />
... //Your code
</View>

refferance :
https://facebook.github.io/react-native/docs/statusbar

Answer:

Add this code on your header component

androidStatusBarColor="#34495e"

Answer:

There is no way currently to do that from JS. You can customize it by using a custom theme. Check out android/src/main/res/values/styles.xml file from your project (template is here: https://github.com/facebook/react-native/blob/master/local-cli/generator-android/templates/src/app/src/main/res/values/styles.xml) and read more here: https://developer.android.com/training/material/theme.html

Answer:

There is no exposed API for now. This will work only from Android 5.0.
Working on a bridge module to achieve the same. Will keep you posted

Answer:

If you are using Expo for React Native then here is the solution for setting Android Status Bar Color.

First of all, In your app.json file add the code:

{
  "expo": {
    "sdkVersion": "Your given Version",
    "androidStatusBar": {
       "backgroundColor": "#4e2ba1" (Your desirable android Status Bar Color before the app loads)
    }
   }    
}

And then Go to Your Main Component or App.js, import ‘StatusBar’ from ‘react-native’. Then add Following Code in return:

return(
   <View style={{flex: 1}}>  (Do not forget to style flex as 1)
      <StatusBar translucent backgroundColor="rgba(0,0,0,0.2)"/>
      <Your Code>
   </View>
);

Here, we are setting the status bar color as Black but with 0.2 opacity. Your statusBar Color will be the same as your headerStyle background Color for Stack Navigator but a bit darker. For standard Android App, this is how the StatusBar color is set. Also, Make it translucent so that your app draws under the status Bar and looks nice.

It hope this works perfectly for you.

Answer:

Just add the following code to your App.js file inside your class component.

    componentDidMount(){
        StatusBar.setBarStyle( 'light-content',true)
        StatusBar.setBackgroundColor("Your color Hex-code here")
    }

And add this to your import statements.

    import {StatusBar} from 'react-native';

Answer:

add color.xml in ..android/app/src/main/res/values and pate following code

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--   color for the app bar and other primary UI elements -->
    <color name="colorPrimary">#3F51B5</color>

    <!--   a darker variant of the primary color, used for
           the status bar (on Android 5.0+) and contextual app bars -->
    <color name="colorPrimaryDark">#A52D53</color>

    <!--   a secondary color for controls like checkboxes and text fields -->
    <color name="colorAccent">#FF4081</color>
</resources>

copy and pate following code in ..android/app/src/main/res/values/styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
   <!-- Customize your theme here. -->
   <item name="colorPrimary">@color/colorPrimary</item>
   <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
   <item name="colorAccent">@color/colorAccent</item>    
</style>

Answer:

If you guys are using expo then just add this in the app.json

"androidStatusBar": {
  "backgroundColor": "#ffffff",
  "barStyle":"dark-content"
}

Refer: https://docs.expo.io/versions/latest/guides/configuring-statusbar/