如何为TouchableOpacity组件应用禁用的样式?
<TouchableOpacity
style={styles.buttonWrapper }
onPress={this.userLogin.bind(this)}
disabled={ !this.state.username || !this.state.password }
>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
如何为TouchableOpacity组件应用禁用的样式?
<TouchableOpacity
style={styles.buttonWrapper }
onPress={this.userLogin.bind(this)}
disabled={ !this.state.username || !this.state.password }
>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
3条答案
按热度按时间7uzetpgm1#
最简单的方法是使用与禁用 prop 相同的条件。
类似这样的方法应该可以奏效:
pgpifvop2#
为
React-Native
或React
中的元素禁用样式的最佳方法如下:查看实际操作:codesandbox
使用这个示例,您不需要为按钮设置重复的样式,只需为
styles.buttonDisabled
中的禁用按钮定义禁用样式(如backgroundColor
或color
)。o2gm4chl3#
你可以用不透明来显示禁用'
'