React Native:如何结合外部和内联样式? [英] React native: How to combine external and inline styles?

查看:32
本文介绍了React Native:如何结合外部和内联样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 _renderRow 函数的一部分.我有一个按钮的一些基本样式,还有一个从行上的变量中读取的样式.在这个例子中它是 '#f00' 但它可以是一个变量,比如 thisColor.如何将外部样式与内联样式结合起来?

This is a part of a _renderRow-function. I have some basic styles for a button, and also a style that is read from a variable on the row. In this example it's '#f00' but it could be a variable, like thisColor. How can I combine an external style with an inline style?

类似的东西,但这不起作用:

Something like this, but this doesn't work:

<TouchableHighlight style={[styles.button]{ backgroundColor: '#f00'}}   

或者我是否必须将它与 TouchableHightlight 内的容器嵌套,然后将内联样式放在该元素上?

Or do I have to nest it with a container inside the TouchableHightlight and put the inline style on that element instead?

推荐答案

你的括号错了.如果您打算继续使用数组语法,请改用:

Your brackets are wrong. If you intend to continue to use the array syntax, Use this instead:

<TouchableHighlight style={[styles.button,{ backgroundColor: '#f00'}]} 

这篇关于React Native:如何结合外部和内联样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆