首页 > 解决方案 > 单击时更改可触摸不透明度内的文本

问题描述

我想将我的可触摸不透明度中的文本更改为新闻事件中的另一个文本。下面是我的代码

<TouchableOpacity
        disabled={this.state.ButtonStateHolder}
        onPress={this.onPressConfirm}
        style={styles.button}
      >
        <View
          style={[
            styles.button1,
            {
              backgroundColor: this.state.ButtonStateHolder
                ? "#607D8B"
                : "#8c0d04"
            }
          ]}
        >
          <Text style={styles.buttontext}>Confirm</Text>
        </View>
      </TouchableOpacity>

在这里,我想将文本确认更改为 Parked on press event。我怎么做

标签: react-nativetexttouchableopacity

解决方案


您必须将状态文本初始化为'Confirm'. TouchableOpacity 将是这样的:

<TouchableOpacity
    disabled={this.state.ButtonStateHolder}
    onPress={() => {this.setState({text: 'Parked'})}}
    style={styles.button}
>
    <View
        style={[
            styles.button1,
            {
                backgroundColor: this.state.ButtonStateHolder
                    ? "#8c0d0488"
                    : "#8c0d04ff"
            }
        ]}
    >
        <Text style={styles.buttontext}>{this.state.text}</Text>
    </View>
</TouchableOpacity>

推荐阅读