【发布时间】:2020-01-02 11:38:47
【问题描述】:
我想更改 TouchableOpacity 的 backgroundColor 和 BorderColor。我知道我可以使用状态来更改 TouchableOpacity BGColor onPress,但是 TouchableOpacitys 是从 arrayList 动态创建的,我只想更改按下的 touchableOpacity 的 backgroundColor 和 BorderCorlor。
这是我创建按钮的代码:
var sizeOptions = [];
for (var i = 0; i < product.Items[0].Items.length; i++) {
for (var j = 0; j < product.Items[0].Items[i].SKUOptions.length; j++) {
if (product.Items[0].Items[i].SKUOptions[j].Alias == 'Tamanho') {
var sizeTitle = product.Items[0].Items[i].SKUOptions[j].Title;
sizeOptions.push(
<TouchableOpacity style={{marginLeft:20, height:40, width:40, borderRadius:1, borderWidth:1, borderStyle: 'solid', borderColor:'#000', backgroundColor:'#fff'}} key = {i} onPress={() => this.selectSize(sizeTitle)}>
<Text style={[{marginTop:10, width:40, height:40, textAlign: 'center'}]}> {sizeTitle} </Text>
</TouchableOpacity>
)
}
}
}
return (
<ScrollView contentContainerStyle={{flexGrow: 1, justifyContent: 'center'}} horizontal={true} style={{marginTop:15, marginLeft: 15}}>
{ sizeOptions }
</ScrollView>
);
此代码已经可以显示创建的按钮,我只需要在按下时更改颜色。
【问题讨论】:
标签: react-native touchableopacity