【发布时间】:2020-05-04 19:57:59
【问题描述】:
我想使用style1的backgroundColor作为状态,并在函数change()中改变它。
如何访问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',
},
});
【问题讨论】:
标签: javascript reactjs react-native react-native-android state