为什么我不能改变状态栏的颜色?

问题描述 投票:0回答:2

这是我的代码:

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-native expo statusbar
2个回答
1
投票

像这样使用。

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

0
投票

正如你在docs中看到的那样,正确的方法是backgroundColor =“white”。也许还有另一个问题。你在哪台设备上测试?尝试没有半透明(我知道它应该工作,但也许你的Android版本有一个错误)。尝试使用rgb颜色(#ff0000)。让我知道你的结果。

© www.soinside.com 2019 - 2024. All rights reserved.