Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StatusBar color in React Native

How can I change background color of StatusBar component from react-native, without editing Android specific files?

Docs says, that I can use backgroundColor property. But it fails. barStyle property, setBarStyle && setBackgroundColor static methods don`t work properly too.

Only hidden property works.

I`m using create-react-native-app, built with Expo.

like image 373
Maxim Romanyuk Avatar asked May 11 '17 14:05

Maxim Romanyuk


People also ask

What is StatusBar in react native?

React Native StatusBar is a component which is used to decorate status bar of the app. It is used by importing the StatusBar component from the react-native library. We can use multiple StatusBar at the same time. <View> <StatusBar.

How do I set the status bar background in react native?

Add import { StatusBar } from 'react-native'; to the top of your app. js and then add StatusBar. setBarStyle('light-content', true); as the first line in your render() to change the status bar text/icons to white. The other color options are 'default' and 'dark-content' .


4 Answers

In Expo App, you need to edit app.json in your project root directory like this:

{
    "expo": {
        "sdkVersion": "16.0.0",
        "androidStatusBar": {
            "barStyle": "dark-content",
            "backgroundColor": "#0A48A5"
        }
    }
}

See Expo documentation: https://docs.expo.io/versions/v16.0.0/guides/configuration.html

like image 87
Rick Liao Avatar answered Oct 27 '22 00:10

Rick Liao


You can use

<StatusBar
 backgroundColor="blue"
 barStyle="light-content"
/>

You can see the documentation here.

like image 32
Antoine Grandchamp Avatar answered Oct 26 '22 23:10

Antoine Grandchamp


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>
like image 21
Mojtaba Darzi Avatar answered Oct 26 '22 22:10

Mojtaba Darzi


use this

import {StatusBar} from 'react-native';


const bar = ()=>{
  return( <StatusBar backgroundColor="insert your color here"/> );
};
like image 36
Aymen Avatar answered Oct 27 '22 00:10

Aymen