Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 一次仅高亮显示一个按钮(react native)_React Native - Fatal编程技术网

React native 一次仅高亮显示一个按钮(react native)

React native 一次仅高亮显示一个按钮(react native),react-native,React Native,我目前有三个可触摸的突出显示按钮,我想一次只突出显示其中一个按钮,并存储它们的状态 声明: state = { selected: null, }; handleClick函数 _handleClick(flag) { if (flag == 1) { this.setState({selected: true}); } } 三个可触摸的亮点之一 <TouchableHighlight style={styles.container

我目前有三个可触摸的突出显示按钮,我想一次只突出显示其中一个按钮,并存储它们的状态

声明:

state = {
    selected: null,
  };
handleClick函数

 _handleClick(flag) {
    if (flag == 1) {
      this.setState({selected: true});
    }
  }
三个可触摸的亮点之一

 <TouchableHighlight
   style={styles.container}
   onPress={() => this._handleClick('any flag')}
   underlayColor="red">
   <View>
      <Text>
         Test
      </Text>
   </View>
 </TouchableHighlight>
this.\u handleClick('any flag')}
参考底图颜色=“红色”>
试验
到目前为止,这只突出显示了当前按钮,我试图点击约一秒钟,底图的颜色变了

有人能帮我吗?
谢谢

您可以尝试使用:

声明:

state = {
    selected: null,
  };
状态={
选中:空,
SelectedButton:“”
};
handleClick功能:

 _handleClick(flag, button) {
    if (flag == 1) {
      this.setState({selected: true});
    }
    this.setState({SelectedButton: button})
  }
 _handleClick(flag, button) {
    if (flag == 1) {
      this.setState({selected: true});
    }
    this.setState({value: 'flag'})
  }
可触摸:

 <TouchableHighlight
   style={styles.container}
   onPress={() => this._handleClick('any flag', '1')}
   underlayColor="red">
   <View style={{backgroundColor: (this.state.SelectedButton === '1' ? 'red' : 'green')}}>
      <Text>
         Test
      </Text>
   </View>
 </TouchableHighlight>
 <TouchableHighlight
   style={[styles.container, { backgroundColor: (this.state.value === 'any flag' ? 'red' : 'green')}]}
   onPress={() => this._handleClick('any flag')}
   underlayColor="red">
   <View>
      <Text>
         Test
      </Text>
   </View>
 </TouchableHighlight>
handleClick功能:

 _handleClick(flag, button) {
    if (flag == 1) {
      this.setState({selected: true});
    }
    this.setState({SelectedButton: button})
  }
 _handleClick(flag, button) {
    if (flag == 1) {
      this.setState({selected: true});
    }
    this.setState({value: 'flag'})
  }
可触摸:

 <TouchableHighlight
   style={styles.container}
   onPress={() => this._handleClick('any flag', '1')}
   underlayColor="red">
   <View style={{backgroundColor: (this.state.SelectedButton === '1' ? 'red' : 'green')}}>
      <Text>
         Test
      </Text>
   </View>
 </TouchableHighlight>
 <TouchableHighlight
   style={[styles.container, { backgroundColor: (this.state.value === 'any flag' ? 'red' : 'green')}]}
   onPress={() => this._handleClick('any flag')}
   underlayColor="red">
   <View>
      <Text>
         Test
      </Text>
   </View>
 </TouchableHighlight>
this.\u handleClick('any flag')}
参考底图颜色=“红色”>
试验