How to change image and text color when clicking using react-native?

前端 未结 3 2198
情话喂你
情话喂你 2021-02-19 03:43

I am using TouchableHighlight, but I can change only background color using underlayColor. But how to change other content?

3条回答
  •  醉话见心
    2021-02-19 04:04

    This answer is assuming you want to change the color just while the button is depressed:

    Use TouchableWithoutFeedback and define your own onPressIn and onPressOut functions to change the text color.

     
      MyText
    
    
    colorText: function() {
      this.setState({textColored: true});
    },
    resetText: function() {
      this.setState({textColored: false});
    },
    textColored: function() {
      if(this.state.textColored) {
        return styles.textColored;
      } else {
        return styles.textNormal;
      }
    }
    

提交回复
热议问题