android - React Native 样式问题。不变违例
问题描述
在本机反应中,我正在使用以下样式设置组件
const style = StyleSheet.create({
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
})
但它给出了错误:
这似乎borderBottomColor
是一个有效的属性。我找不到错误的原因。
如果直接添加样式。即,没有StyleSheet.create
那么一切都运行完美,风格也得到应用
const style = {
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
}
是否建议在 react native 中直接使用样式?
解决方案
您的使用StyleSheet.create
不太正确。尝试:
const styles = StyleSheet.create({
foo : {
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
}
})
然后将其引用为styles.foo
,如:
<View style={styles.foo} />
您还可以像这样组合样式表和内联样式:
<View style={[styles.foo,{backgroundColor:'green'}]}/>
最后,样式表可以有多个命名样式,例如:
const styles = StyleSheet.create({
foo : {
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
},
bar : {
width:50
}
})
推荐阅读
- sql - 用符号“|”将数据分成一列 到 Oracle SQL 中的多个列
- python - 条形图的颜色与散点图相同
- python - 如何在 RPI4 上将 Python 3.7 降级到 3.6
- graph - 单源最短路径
- c# - 在非 UI 应用程序中,如何处理“调用线程无法访问此对象,因为不同的线程拥有它”
- amazon-cognito - 如何将 OpenID 身份验证从 Blazor WebAssembly 传递到 .NET Core WebApi 后端,两者都使用 Cognito 作为 OpenID 提供程序?
- node.js - 运行“create-react-app my-app”后尝试运行“npm start”时出现一堆错误
- c++ - 可变数据结构模板实例化
- node.js - 无法在本地使用 NodeJS 连接到 AWS DocumentDB
- python - 使用 Haar Cascade(或 LBP)或其他方法进行专业爆头检测