首页 > 解决方案 > 为什么我不能更改状态栏的颜色?

问题描述

这是我的代码:

import React, { Component } from 'react';
import {StatusBar,Platform,Text,StyleSheet,View} from 'react-native';

export default class TabsScrollableExample extends Component {
  render() {
    return (
        <View style={styles.container}>
        <StatusBar 
        barStyle = "light-content" 
        hidden = {false}
        style={styles.color} // I've also tried this way backgroundColor="white"
        translucent = {true}
        networkActivityIndicatorVisible = {true}
        />
 </View>
      
    );
  }
}
const styles = StyleSheet.create({
 
  container :{
  backgroundColor:"white", 
  },
  color:{
    backgroundColor:"white"
  }
   
  });

所有其他属性都可以正常工作,但背景颜色不会改变。

我不知道问题出在哪里。

标签: react-nativeexpostatusbar

解决方案


像这样使用。

<StatusBar 
    barStyle = "light-content" 
    hidden = {false}
    backgroundColor="white"
    translucent = {true}
    networkActivityIndicatorVisible = {true}
    />

推荐阅读