react-native - 为什么 backgroundColor 不适用于 React Native 中的 View?
问题描述
我正在尝试制作一个顶级菜单并为其着色,但backgroudColor
属性不起作用。
<View>
<View style={{
flex: 1,
height: 50,
flexDirection: 'row',
justifyContent: 'space-between',
backgroundColor: 'skyblue'
}}>
<View style={{flex: 1, backgroundColor: 'skyblue'}}><Text style={style.upMenu.text}>H</Text></View>
<View style={{flex: 1, backgroundColor: 'skyblue'}}><Text style={style.upMenu.text}>Plugins</Text></View>
<View style={{flex: 1, backgroundColor: 'skyblue'}}><Text style={style.upMenu.text}>Remote</Text></View>
<View style={{flex: 1, backgroundColor: 'skyblue'}}><Text style={style.upMenu.text}>P</Text></View>
</View>
</View>
解决了
非常感谢,您的回答都非常有用!
解决方案
使用下面的代码,
<View style={{ flex: 1 }}>
<View
style={{
flex: 1,
height: 50,
flexDirection: "row",
justifyContent: "space-between",
backgroundColor: "#87ceeb",
maxHeight: 20
}}
>
<View style={{ flex: 1, backgroundColor: "#87ceeb" }}>
<Text style={style.upMenu.text}>H</Text>
</View>
<View style={{ flex: 1, backgroundColor: "#87ceeb" }}>
<Text style={style.upMenu.text}>Plugins</Text>
</View>
<View style={{ flex: 1, backgroundColor: "#87ceeb" }}>
<Text style={style.upMenu.text}>Remote</Text>
</View>
<View style={{ flex: 1, backgroundColor: "#87ceeb" }}>
<Text style={style.upMenu.text}>P</Text>
</View>
</View>
</View>
要获得所需的标题高度,请使用maxHeight
来更改它
推荐阅读
- google-app-engine - 将 AppEngine 中的传入请求路由到不同版本
- python - 如何使用 GIT 配置 RFlinter 以在每次提交时自动对机器人文件运行 linter 检查
- sql - EF Core 3.1 - 数据库优先和继承
- laravel - 具有许多内部连接的最慢查询使其更快 postgres
- javascript - 从 localStorage 中检索对象适用于控制台日志,但不适用于页面
- azure-devops - Azure DevOps 添加概述
- image - 在 Bootstrap Carousel 中为图像设置相等的高度
- r - names_to '.value' 约定如何适用于 pivot_longer 中每行的多个观察值?
- terraform - 如何将基于 Terraform 的软件添加到 IBM Cloud 的私有目录?
- reactjs - TypeError:null 不是对象(评估'_RNGestureHandlerModule.default.Direction')