Skip to content
Related Articles
Open in App
Not now

Related Articles

React Native StatusBar Component

Improve Article
Save Article
  • Last Updated : 10 May, 2021
Improve Article
Save Article

The following approach covers how to control StatusBar in react-native. For this, we are going to use the StatusBar component. It is an interface at the top of the screen that displays the notification icons.



Props in StatusBar:

  • animated: If the transition between status bar property changes should be animated.
  • backgroundColor: It is the background color of the status bar. It is only for android devices.
  • barStyle: It sets the color of the status bar text.
  • hidden: It hides the status bar.
  • networkActivityIndicatorVisible: If the network activity indicator should be visible. It is only for IOS devices.
  • showHideTransition: The transition effect when showing and hiding the status bar using the hidden prop.
  • translucent: If true, then the app will draw under the status bar.

Methods in StatusBar:

  • popStackEntry(): It gets and removes the last StatusBar entry from the stack.
  • pushStackEntry(): It pushes a StatusBar entry onto the stack.
  • replaceStackEntry(): It replaces an existing StatusBar stack entry with new props.
  • setBackgroundColor(): It set the background color for the status bar. It is only available for android devices.
  • setBarStyle(): It set the status bar style.
  • setHidden(): It shows or hides the status bar.
  • setNetworkActivityIndicatorVisible(): It controls the visibility of the network activity indicator. It is only available for IOS devices.
  • setTranslucent(): It controls the translucency of the status bar.

Now let’s start with the implementation:

  • Step 1: Open your terminal and install expo-cli by the following command.

    npm install -g expo-cli
  • Step 2: Now create a project by the following command.

    expo init myapp
  • Step 3: Now go into your project folder i.e. myapp

    cd myapp

Project Structure: It will look like the following.

Example: Now let’s implement the StatusBar. Here we created two buttons, the first button hides the status bar and the second button change’s the style of the status bar.



import React , {useState} from 'react';
import { StyleSheet, View , Button , StatusBar } from 'react-native';
const STYLE = ['default', 'dark-content', 'light-content'];
export default function App() {
  let index = 0;
  const [hidden , sethidden] = useState(false);
  const [styleBar , setBar] = useState(STYLE[0]);
  const changeStyle = () => {
    index += 1;
    if(index == 3)
      index = 0;
  return (
    <View style={styles.container}>
        <View style={styles.button}>
          title={"Hide StatusBar"}
        <View style={styles.button}>
          title={"Change Style"}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  text : {
    fontSize : 40,
    marginBottom : 30
  button : {
    margin : 20,

Start the server by using the following command.

npm run android

Output: If your emulator did not open automatically then you need to do it manually. First, go to your android studio and run the emulator. Now start the server again. 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!