Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29766

How to change color of Switch toggle button using state?

$
0
0

If I have a Switch component as follows;

<Switch                trackColor={{ false: '#e57373', true: '#81c784' }}                thumbColor='gray'                ios_backgroundColor="gray"                onValueChange={(value) => this.setState({ toggle: value })}                value={this.state.toggle}            />

Can I change the color using a state value I have set e.g

 componentDidMount() {    backgroundColor = this.props.dataBackgroundColor;    primaryColor = this.props.dataPrimaryColor;    this.setState({ background_color: backgroundColor })    this.setState({ primary_color: primaryColor })     console.log(this.state.primary_color) // This print correct color}

And then do something like;

<Switch                trackColor={{ false: '#e57373', true: this.state.primary_color }}                thumbColor='gray'                ios_backgroundColor="gray"                onValueChange={(value) => this.setState({ toggle: value })}                value={this.state.toggle}            />

At the moment, no error is thrown but the color is not updated.


Viewing all articles
Browse latest Browse all 29766

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>