如何在 React Native Expo 中使用 styleSheet 应用样式
How to apply styles using styleSheet in react native expo
我正在尝试在我的 React Native 应用程序中应用一些样式,但它对我不起作用,我尝试在浏览器中 运行 它是显示的输出:
但是当我 运行 它在我的 phone 中时,它向我显示错误:
这是主要的 App.js 文件:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { View } from 'react-native';
import HomeMenu from './src/screens/Home/index';
export default function App() {
return (
<View style={{ flex: 1 }}>
<StatusBar style="auto" />
<HomeMenu />
</View>
);
}
这是 index.js 文件(我想显示其结果的文件):
import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
const HomeMenu = () => {
return (
<SafeAreaView style={{ flex: 1 }}> //add flex:1 here
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
</SafeAreaView>
);
};
export default HomeMenu;
const styles = StyleSheet.create({
container: {
flex: 3,
backgroundColor: '#21534A',
alignItems: 'center',
justifyContent: 'center',
},
});
如果您知道我的代码有什么问题,请告诉我。
试试这样:-
import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
const HomeMenu = () => {
return (
<SafeAreaView style={{ flex: 1 }}>
//add flex:1 here
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
</SafeAreaView>
);
};
export default HomeMenu;
const styles = StyleSheet.create({
container: {
flex: 3,
backgroundColor: '#21534A',
alignItems: 'center',
justifyContent: 'center',
},
});
我正在尝试在我的 React Native 应用程序中应用一些样式,但它对我不起作用,我尝试在浏览器中 运行 它是显示的输出:
但是当我 运行 它在我的 phone 中时,它向我显示错误:
这是主要的 App.js 文件:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { View } from 'react-native';
import HomeMenu from './src/screens/Home/index';
export default function App() {
return (
<View style={{ flex: 1 }}>
<StatusBar style="auto" />
<HomeMenu />
</View>
);
}
这是 index.js 文件(我想显示其结果的文件):
import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
const HomeMenu = () => {
return (
<SafeAreaView style={{ flex: 1 }}> //add flex:1 here
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
</SafeAreaView>
);
};
export default HomeMenu;
const styles = StyleSheet.create({
container: {
flex: 3,
backgroundColor: '#21534A',
alignItems: 'center',
justifyContent: 'center',
},
});
如果您知道我的代码有什么问题,请告诉我。
试试这样:-
import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
const HomeMenu = () => {
return (
<SafeAreaView style={{ flex: 1 }}>
//add flex:1 here
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
</SafeAreaView>
);
};
export default HomeMenu;
const styles = StyleSheet.create({
container: {
flex: 3,
backgroundColor: '#21534A',
alignItems: 'center',
justifyContent: 'center',
},
});