[英]How to change only the active button background color [React-Native]
[英]change background color with a button react-native
我正在嘗試通過單擊按鈕來更改我的視圖背景顏色。 但是什么也沒發生(沒有錯誤)。
export default class App extends React.Component{
state = {
color: "#fff"
}
render() {
return(
<View style={{backgroundColor: this.state.color, flex: 1, alignItems:'center', justifyContent:'center',}}>
<Button onClick={() => { this.setState({color: "#00ff00" }) }} title="selam"></Button>
</View>
);
}
};
您必須使用 onPress 而不是 onClick
<Button onPress={() => { this.setState({color: "#00ff00" }) }} title="selam"></Button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.