例如,我有 3 个带边框的按钮,当我按下其中的 2 个按钮时,其中 2 个按钮会将其样式更改为颜色填充按钮。
我应该使用<Button>
或<TouchableHighlight>
或<TouchableOpacity>
或其他人?
我需要在 React Native 中为此提供示例代码。
没关系,您可以使用所有这些我通常在单击按钮时使用这种方法我像这样更改触发组件的状态
默认状态: this.state = { styleIndex: 0 }
<Button
onPress={this.press}
style={this.state.styleIndex === 0 ? styles.buttonStyle : styles.buttonStyleClicked}/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句