reactjs 容器视图上的React Native更改背景色不起作用

aij0ehis  于 2023-01-25  发布在  React
关注(0)|答案(1)|浏览(120)

我是新的React Native。我试图改变容器的背景视图似乎不起作用。我附上了下面的代码。有人能告诉我下面的代码有什么问题吗?

const HomeScreen = () => {
  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1, backgroundColor: '#FF0000' }}>
        <Text style={{
          color: COLORS.Text,
          marginLeft: 14,
          marginTop: 16,
          width: 100,
          height: 20
        }}>Hello world</Text>
      </View>
    </SafeAreaView>
  );
pod7payv

pod7payv1#

检查以下代码:

import React from 'react';
import {StyleSheet, Text, SafeAreaView } from 'react-native';

const App = () => {
  return (
    <SafeAreaView style={styles.container}>
      <Text style={styles.text}>Page content</Text>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor:'green'
  },
  text: {
    fontSize: 25,
    fontWeight: '500',
  },
});

export default App;

有关详细信息,可以浏览SafeArea Documentation.

相关问题