我希望在函数 change()
中将style1
的backgroundColor
用作状态,并进行更改。
我该怎么访问 style1
?
我的意图是从另一个函数调用函数change
,使按钮将其颜色更改为黄色,然后再过一段时间将其颜色再次更改为蓝色。
export default class App extends Component{
constructor (props){
super(props);
this.state = {
//style1.backgroundColour: blue //? Can't
}
this.change=this.change.bind(this)
}
change() {
this.setState({ style1.backgroundColour: yellow }) //?
}
render(){
return (
<View style={styles.style1} > </View>
);
}
}
const styles = StyleSheet.create({
style1:{
padding: 5,
height: 80,
width: 80,
borderRadius:160,
backgroundColor:'blue',
},
});