Android 回应本地样式问题。不变违反
在react native中,我正在使用下面的样式设置组件的样式Android 回应本地样式问题。不变违反,android,reactjs,react-native,Android,Reactjs,React Native,在react native中,我正在使用下面的样式设置组件的样式 const style = StyleSheet.create({ height: 100, borderBottomWidth: 1, borderBottomColor: "rgb(201, 204, 204)" }) 但它给出了错误: 似乎borderBottomColor是一个有效的属性。我找不出出错的原因 如果直接添加样式。i、 例如,没有样式表。创建之后,一切都会完美运行,样式也会得到应用
const style = StyleSheet.create({
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
})
但它给出了错误:
似乎borderBottomColor
是一个有效的属性。我找不出出错的原因
如果直接添加样式。i、 例如,没有样式表。创建之后,一切都会完美运行,样式也会得到应用
const style = {
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
}
建议直接在react native中使用样式吗?您使用的样式表。create
不太正确。尝试:
const styles = StyleSheet.create({
foo : {
height: 100,
borderBottomWidth: 1,
borderBottomColor: "rgb(201, 204, 204)"
}
})
然后将其引用为styles.foo
,如中所示:
<View style={styles.foo} />
这个应用到的元素是什么?并不是所有人都能做到borders@Kai这是视图,如果我不使用样式表,则样式适用。创建
好的,它起作用了,但您能否解释一下有关样式表的更多信息。创建
。它确切地做了什么,而不是返回传递给它的同一个对象?我没有深入研究它,但它只是在使用styles.foo
时返回一个id,而不是实际的对象(可以使用Stylesheet.flatte(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
}
})