簡體   English   中英

反應本機狀態欄不適用於android中的反應導航

[英]React native statusbar not working with react-navigation in android

版本:

   "native-base": "^2.4.2",
    "react": "16.3.1",
    "react-native": "0.55.2",
    "react-native-global-font": "^1.0.1",
    "react-native-router-flux": "^4.0.0-beta.28",
    "react-navigation": "^1.5.11"

當我添加反應導航時,我無法更改狀態欄顏色,我的狀態欄變為藍色。

這是我的 Navigationview.js 代碼

    render() {
          return (
            <Root style={styles.container}>
                <StatusBar
                  backgroundColor="white"
                  barStyle="dark-content"
                />
                <MainView />
            </Root>
          );
        }

    const drawerHeader = (props) => (
  <Container style={styles.container}>
    <Header style={styles.header}>
      <Body style={styles.body}>
        <Icon name="person" style={{ fontSize: 40, color: '#CCCCCC' }} />
      </Body>
    </Header>
    <Content>
    <SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}>
        <DrawerItems {...props} />
        <Button title="Logout" onPress={() => Actions.reset('login')} />
    </SafeAreaView>
    </Content>
  </Container>
);

    const MainView = DrawerNavigator({
      DASHBOARD: {
        screen: Dashboard,
      },
      LOGOUT: {
        screen: LoginForm,
      }
    }, {
        initialRouteName: 'DASHBOARD',
        contentComponent: drawerHeader,
        drawerOpenRoute: 'DrawerOpen',
        drawerCloseRoute: 'DrawerClose',
        drawerToogleRoute: 'DrawerToogle'
    });

i even set statusbar color in Dashboard screen, still not change.

Dashboard.js

    <Container>
            <Header androidStatusBarColor="#FFF" style={{backgroundColor:'#000'}}>
              <StatusBar
                  backgroundColor="white"
                  barStyle="dark-content"
                />
              <Body>
                <Title style={{color:'#FFF'}}>My App</Title>
              </Body>
            </Header>
            <Content>
              //content of your app goes here
            </Content>
          </Container>
I m also using native-base, so i add this code in my App.js file

    render() {
        return (
          <Root style={styles.container}>
              <StatusBar
                backgroundColor="white"
                barStyle="dark-content"
              />
              {this.spinerRender()}
          </Root>
        );
      }

這適用於我的登錄和登錄屏幕,但不適用於我的導航視圖屏幕。

登錄和登錄屏幕狀態欄

在此處輸入圖像描述

導航屏幕狀態欄

在此處輸入圖像描述

它現在修復了。

問題,是原生組件,所以我將 contentComponent 視圖更改為此。

<SafeAreaView style={{flex: 1}}> 
<View style={styles.container}> 
   <StatusBar backgroundColor={'red'} barStyle={'dark-content'} translucent={false} /> 
.... 
</SafeAreaView>

我的問題略有不同。

我導航的上一個屏幕已將StatusBar hidden 設置為 true。

// previous screen that I navigated from
<StatusBar hidden animated /> 

因此,我必須在新屏幕上將StatusBar hidden 顯式更改為false並將animated更改為true

// new screen needs hidden={false} to show up
<StatusBar hidden={false} animated />

對於任何使用本機基礎 Header 並遇到此問題的人,您可以使用道具 iosBarStyle,如下所示

    <Header
      iosBarStyle="dark-content"

對於使用本機基礎Header並遇到此問題的任何人,您可以使用道具androidStatusBarColor ,如下所示

<Header style={styles.header} androidStatusBarColor="#f8bb12">

如果存在缺口,您可以這樣做以排除缺口。

import React from "react";
import {Text, SafeAreaView, StatusBar} from "react-native";

export default function App() {
  return (
    <React.Fragment>
      <StatusBar hidden />
      <SafeAreaView> 
        <Text>Your Code</Text>
      </SafeAreaView>
    </React.Fragment>
  );
}

通過使用帶隱藏的 StatusBar 可以排除一流的。

反應本機應用程序中的狀態欄顏色

<View>
    <StatusBar backgroundColor="red"></StatusBar>

     <Text>
           hii
     <Text>

</View>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM