Is there a way to change the Android status bar co

2020-05-24 19:33发布

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

11条回答
相关推荐>>
2楼-- · 2020-05-24 20:10

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.

查看更多
女痞
3楼-- · 2020-05-24 20:12

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';
查看更多
男人必须洒脱
4楼-- · 2020-05-24 20:14

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/

查看更多
做自己的国王
5楼-- · 2020-05-24 20:16

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

查看更多
甜甜的少女心
6楼-- · 2020-05-24 20:16

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

查看更多
Explosion°爆炸
7楼-- · 2020-05-24 20:16

Add this code on your header component

androidStatusBarColor="#34495e"
查看更多
登录 后发表回答