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

前端 未结 3 2205
情话喂你
情话喂你 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:02

    With TouchableHighlight you can do it like this

    state = { selected: false };
    
    setSelected(selected: boolean) {
        this.setState({ selected: selected });
    }
    
    textStyle() {
        return this.state.selected ? styles.textSelected : styles.text;
    }
    

    And then in the render function

     onPress()}
        onShowUnderlay={() => this.setSelected(true)}
        onHideUnderlay={() => this.setSelected(false)}
    >
        {text}
    
    

提交回复
热议问题