简体   繁体   中英

react native, remove stack navigation color from android status bar

I created a stack navigation and customize is background color to black, but I'm getting a problem that stack navigator color is also applying to android status bar element. It's applying color to every detail in my status bar like time battery therefore it's not visible, see image below. How can I fix this

在此处输入图片说明

const Stack = createStackNavigator();

export default function AppNavigation ()
{
    return (
        <Stack.Navigator screenOptions={{ headerStyle: { backgroundColor: colors.black } }} >
            <Stack.Screen name="Home" component={Home} options={({ navigation }) =>
            {
                return {
                    headerTitle: () => <Header name="Shop" navigation={navigation} />,
                };
            }} />
        </Stack.Navigator>
    );
}

You have a StatusBar module in react native https://reactnative.dev/docs/statusbar

You can use it to change android statusBar color

for example

<StatusBar backgroundColor="blue" barStyle='light-content' />

You could position your navigation bar below the android bar. I would only do this if you are working on a particular device that you know what the size of the status bar would be though. Else use https://reactnative.dev/docs/statusbar

Example

const styles = StyleSheet.create({
  main: {
    flex: 1,
    backgroundColor: "#FCFCFC",
    marginTop: 24,
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM