Color StatusBar in React Native

How to change the background color of a StatusBarcomponent from react-nativewithout editing specific Android files?

Docs says I can use backgroundColor. But that fails. barStyle, setBarStyle&& & setBackgroundColorstatic methods do not work properly.

Only the property works hidden.

I use create-react-native-appbuilt using Expo .

+5
source share
4 answers

In the Expo App, you need to edit app.jsonthe root directory of your project as follows:

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

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

+7

color.xml ..android/app/src/main/res/values

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

..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>
+3

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

.

+2

import {StatusBar} from 'react-native';


const bar = ()=>{
  return( <StatusBar backgroundColor="insert your color here"/> );
};
+1

Source: https://habr.com/ru/post/1676921/


All Articles