我尝试使用flex: 1
用黑色填充整个屏幕。但结果是这样的
<View
style={{
flex: 1,
backgroundColor: 'black',
}}
/>
我也尝试使用:
height: '100%',
width: '100%',
和
const HEIGHT = Dimensions.get('window').height;
const WIDTH = Dimensions.get('window').width;
但结果仍然相同。
有没有办法完全填满整个屏幕?
声明一个常量
const HEIGHT = Dimensions.get('window').height;
const WIDTH = Dimensions.get('window').width;
然后使用此内部样式
style = {{ height = HEIGHT, width = WIDTH, backgroundColor = 'black', }}
style = {{ width:'100%', height:'100%' }}
render() {
return (
<View style={{ flex: 1, backgroundColor: 'black'}} />
)
}
import { StatusBar } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
将布局更改为:
<StatusBar backgroundColor="black" barStyle="white-content"/> <SafeAreaView style={{ flex: 1, backgroundColor: 'black', }} > <View>...</View> </SafeAreaView>