美文网首页
react native 针对每个页面不同的StatusBar

react native 针对每个页面不同的StatusBar

作者: AINIDEXIN | 来源:发表于2019-01-13 16:34 被阅读0次

官网参考地址:Different status bar configuration based on route · React Navigation

新的版本将不再使用StatusBar组件,而使用SafeAreaView。

直接上代码:

Home页面

import React, { Component } from "react";

import {

  StyleSheet,

  Text,

  Image,

  View,

  StatusBar,

  SafeAreaView,

  isAndroid

} from "react-native";

import Headerapp from "./components/Header";

export default class Index extends Component {

  render() {

    return (

      <SafeAreaView style={{backgroundColor:'#e12828',height:1}}>

        <View style={styles.container}>

          <Headerapp />

        </View>

      </SafeAreaView>

    );

  }

  componentDidMount() {

    this._navListener = this.props.navigation.addListener('didFocus', () => {

      StatusBar.setBarStyle('light-content'); //状态栏文字颜色

      StatusBar.setBackgroundColor('#e12828'); //状态栏背景色

    });

  }

  componentWillUnmount() {

    this._navListener.remove();

  }

}

const styles = StyleSheet.create({

  container: {

    flex: 1

  }

});

Video页面:

import React, { Component } from "react";

import {

  AppRegistry,

  StyleSheet,

  Text,

  Image,

  View,

  TouchableOpacity,

  SafeAreaView,

  StatusBar,

  isAndroid

} from "react-native";

export default class Index extends Component {

  render() {

    return (

      <SafeAreaView style={{backgroundColor:'#9626e4'}}>

        <View style={styles.container}>

          <Text>视频界面</Text>

        </View>

      </SafeAreaView>

    );

  }

  componentDidMount() {

    this._navListener = this.props.navigation.addListener("didFocus", () => {

      StatusBar.setBarStyle("dark-content"); //状态栏文字颜色

      StatusBar.setBackgroundColor("#ffffff"); //状态栏背景色

    });

  }

  componentWillUnmount() {

    this._navListener.remove();

  }

}

const styles = StyleSheet.create({

  container: {

    flex: 1,

    backgroundColor: "#F5FCFF"

  }

});

相关文章

网友评论

      本文标题:react native 针对每个页面不同的StatusBar

      本文链接:https://www.haomeiwen.com/subject/pktdbftx.html