【发布时间】:2017-06-29 03:48:11
【问题描述】:
我想让按钮在按下时改变它的颜色。我尝试查看其他类似主题,但找不到解决方案。代码呈现,初始按钮颜色为红色,但当我按下它时,什么也没有发生。
export default class someProgram extends Component {
render() {
var buttonColor = "red";
function changeButtonColor(){
if(this.buttonColor === "red"){
this.buttonColor = "green";
}
else{
this.buttonColor = "red";
}
}
return (
<View style={styles.container}>
<Button
title="Press me!"
color={buttonColor}
onPress={() => {changeButtonColor(buttonColor)}}
/>
</View>
);
}
}
【问题讨论】:
标签: android button colors react-native