GVKun编程网logo

使用React Native隐藏状态栏(react native 状态栏)

11

对于想了解使用ReactNative隐藏状态栏的读者,本文将是一篇不可错过的文章,我们将详细介绍reactnative状态栏,并且为您提供关于React-Native状态栏文件居中、ReactNati

对于想了解使用React Native隐藏状态栏的读者,本文将是一篇不可错过的文章,我们将详细介绍react native 状态栏,并且为您提供关于React -Native 状态栏文件居中、React Native Desktop:使用React Native构建OS X桌面应用、React Native ios 设置状态栏文本颜色、React Native IOS状态栏背景的有价值信息。

本文目录一览:

使用React Native隐藏状态栏(react native 状态栏)

使用React Native隐藏状态栏(react native 状态栏)

使用React
Native开发时如何隐藏iOS或Android的状态栏?我已经导入了StatusBar,但是我相信还有StatusBarIOS和一个StatusBar
for Android。

答案1

小编典典

弄清楚如何隐藏状态栏。首先,不建议使用
StatusBarIOS,因此您需要导入StatusBar,然后只需在渲染顶部包括以下代码段即可:

<StatusBar hidden />

在上响应本机文档 StatusBar

React -Native 状态栏文件居中

React -Native 状态栏文件居中

代码:

var StackHomeOptions =({navigation})=>{

    let {state} = navigation;
    console.log('Home navigation:'+navigation+state.params);
    const headerStyle = ETTHeaderStyles.headerStyle;
    const headerTitle = '北京';
    const headerTitleStyle = ETTHeaderStyles.headerTitleStyle;
    const headerBackTitle = '返回';
    const headerRight= (<Button onPress={() => navigation.navigate('MyScene',{
        title:'个人中心'
    })} title={'详情'} />);
    const headerLeft =(<View/>);
    return {headerTitle,headerRight,headerTitleStyle,headerStyle,headerBackTitle,headerLeft}
};

style:

var ETTHeaderStyles = StyleSheet.create(
    {
        headerStyle: {
            backgroundColor: '#1C1D21'
        },headerTitleStyle: {
            flex:1,alignSelf:'center',fontSize: 20,color: '#ffffff',textAlign: 'center',fontSize: 20
        },bigTextPrompt: {
            width: 300,backgroundColor: 'gray',color: 'white',});


问题 1。 因为是首页 所以 右侧有按钮 左侧没有按钮 所以会出现title 向左偏移问题 :

解决办法:在 StackHomeOptions 中 增加 const headerLeft =(<View/>);

问题2. 在 ETTHeaderStyles 中headerTitleStyle 设置了 alignSelf:'center',安卓还是不能够居中

解决办法ETTHeaderStyles 中headerTitleStyle 设置

{
flex:1,

alignSelf:'center',

}

React Native Desktop:使用React Native构建OS X桌面应用

React Native Desktop:使用React Native构建OS X桌面应用

React Native ios 设置状态栏文本颜色

React Native ios 设置状态栏文本颜色





<StatusBar backgroundColor="#FFFFFF" bar/>

React Native IOS状态栏背景

React Native IOS状态栏背景

由于将backgroundColor props应用于StatusBar组件,因此未在 IOS上应用.我需要设置SafeAreaView的背景颜色以获得我想要的效果,它工作正常但在iPhone X上它将在屏幕底部具有相同的颜色.我该如何解决这个问题?

enter image description here

解决方法

React-Native不支持iOS平台上StatusBar的背景颜色变化,但在Android平台上,没关系( https://facebook.github.io/react-native/docs/statusbar#backgroundcolor).我为你的问题写了一个解决方法.你可以安全地使用它

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

const STATUS_BAR_HEIGHT = Platform.OS === ''ios'' ? 20 : StatusBar.currentHeight;

function StatusBarPlaceHolder() {
    return (
        <View style={{
            width: "100%",height: STATUS_BAR_HEIGHT,backgroundColor: "blue"
        }}>
            <StatusBar
                bar/>
        </View>
    );
}

class App extends Component {
    render() {
        return (
            <View style={{flex: 1}}>
                <StatusBarPlaceHolder/>
                ...YourContent
            </View>
        );
    }
}

export default App;

对于SafeAreaView:

import React,Platform} from "react-native";
import SafeAreaView from "react-native-safe-area-view";
//You can also use react-navigation package for SafeAreaView with forceInset.

const STATUS_BAR_HEIGHT = Platform.OS === ''ios'' ? 20 : StatusBar.currentHeight;

function StatusBarPlaceHolder() {
    return (
        <View style={{
            width: "100%",backgroundColor: "blue"
        }}>
            <StatusBar
                bar/>
        </View>
    );
}

class App extends Component {
    render() {
        return (
            <SafeAreaView style={{flex:1}}
                forceInset={{top: ''never''}}>
                <StatusBarPlaceHolder/>
                ...YourContent
            </SafeAreaView>
        );
    }
}

export default App;

我们今天的关于使用React Native隐藏状态栏react native 状态栏的分享已经告一段落,感谢您的关注,如果您想了解更多关于React -Native 状态栏文件居中、React Native Desktop:使用React Native构建OS X桌面应用、React Native ios 设置状态栏文本颜色、React Native IOS状态栏背景的相关信息,请在本站查询。

本文标签: