38

Does anyone know a way to make Android Status Bar transparent with React Native?

NOT TRANSLUCENT, Transparent.

I am using react-navigation too.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Giorgos Kartalis
  • 874
  • 1
  • 7
  • 14

9 Answers9

105

Just use it like this: Tested with: "react-native": "0.60.4" and "0.61.5"

<StatusBar translucent backgroundColor="transparent" />
Felipe Rugai
  • 1,289
  • 1
  • 8
  • 14
  • 3
    I've tried this and it working fine in iOS but in android not (`StatusBar._updatePropsStack`: Color transparant parsed to null or undefined) – Akshay I Dec 23 '19 at 10:11
  • 1
    transparant or transparent? – Felipe Rugai Jan 02 '20 at 22:15
  • as per react native docs, https://reactnative.dev/docs/statusbar#translucent-android, translucent defaults to false, so you need to set as `translucent={true}` – funtkungus Jan 31 '22 at 22:36
  • As per React JSX [documentation](https://reactjs.org/docs/jsx-in-depth.html#props-default-to-true) setting `` or `` is the same thing. – Felipe Rugai Mar 22 '22 at 20:51
11

This is working for me on android

<StatusBar
   backgroundColor="transparent"
   translucent={true}
/>
Mouad Tahir
  • 450
  • 6
  • 9
5

Unless you are using Statusbar as a component, try this method.

useFocusEffect(
    useCallback(() => {
      StatusBar.setBarStyle("dark-content");
      Platform.OS === 'android' && StatusBar.setBackgroundColor('transparent');
      StatusBar.setTranslucent(true);
    }, []),
  );

Do not forget to give some paddingTop to the most outer View.

enestatli
  • 535
  • 1
  • 9
  • 19
4

<StatusBar translucent backgroundColor="transparent" /> is the way to go, thx to @Felipe Rugai

However, 2 things to know:

  1. If you are using <Header /> component from react-native-elements, it already have <StatusBar /> included, using its statusBarProps instead.
  2. If you are using WIX react-native-navigation, they have a separate way to dealing with the status bar, refer to this and this. They said it is incompatible with React Native's , however, looks like they work well together for me.
  3. Also android native code/config discussed in another stackoverflow topic solution will override by <StatusBar /> hence doesn't work well.
balloon
  • 81
  • 2
0

If you're talking about the status bar of the OS (the one you pull down to access wifi/bluetooth/settings etc), try adding this to you MainActivity.java:

private void hideNavigationBar() {
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}

And you can call that^ function in this function from the same MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    hideNavigationBar();
}

However, if you're talking about the StatusBar of the app, try adding this to your App.js file

static navigationOptions = {
    header: null
}
ladder
  • 189
  • 2
  • 9
  • 2
    Both methods are useless. static navigationOptions = { header: null } this is supposed to hide toolbar/topbar not status bar. – hasn Dec 19 '18 at 10:46
0

This solution can solve the issue if you're working with expo in your package JSON /expo configuration: you can add a property to overwrite the default StatusBar for android

"androidStatusBar":{
    "translucent":false
}
Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
-1

you can set it usingStatusBar.setBackgroundColor(Colors.TRANSPARENT);

-2

Try this to make transparent statusbar in android

container: {
      flex:1,
      paddingTop: 20
    },

add display flex and paddingTop to your main View component

Maulana Prambadi
  • 1,015
  • 9
  • 7
-4

In react native, if you are using expo you can go to the app.json file and add status bar color. After this background color of the status bar for the complete app will change.

"androidStatusBar": {
  "backgroundColor": "#105846"
},

Check the linked page.