native react 变颜色 点击_在React Native中按下更改按钮样式(Change button style on press in React Native)...
問 題
我希望我的應(yīng)用中按鈕的樣式在按下時更改。最好的方法是什么?
解決方案
使用 touchablehighlight 。
這里有一個例子:
'use strict';
import react,{
component,
stylesheet,
proptypes,
查看,
文字,
touchablehighlight
}來自"反應(yīng)原生";
導出默認類home extends component {
constructor(props){
super(props);
this.state = {pressstatus:false};
}
_onhideunderlay(){
this.setstate({pressstatus:false});
}
_onshowunderlay(){
this.setstate({pressstatus:true});
}
render(){
return(
lt; view style = {styles.container}gt;
lt; touchablehighlight
activeopacity = {1 }
style = {
this.state.pressstatus
?styles.buttonpress
:styles.button
}
onhideunderlay = {this._onhideunderlay.bind (this)}
onshowunderlay = {this._onshowunderlay.bind(this)}
gt;
lt; text
style = {
this.state.pressstatus
?styles.welcomepress
:styles.welcome
}
gt;
{this.props.text}
lt; / textgt;
lt; / touchablehighlightgt;
lt; / viewgt;
);
}
}
home.proptypes = {
text:proptypes.string.isrequired
};
const styles = stylesheet.create({
容器:{
flex:1,
justifycontent:"center",
alignitems:"center" ,
backgroundcolor:"#f5fcff"
},
歡迎:{
fontsize:20,
textalign:"center",
保證金:10,
顏色:"#000066"
},
welcomepress:{
fontsize:20,
textalign:"center",
保證金:10,
顏色:"#fffffff"
},
按鈕:{
bordercolor:"#000066",
borderwidth:1,
borderradius:10
},
buttonpress:{
bordercolor:"#000066",
backgroundcolor:"#000066",
borderwidth:1,
borderradius:10
}
});
總結(jié)
以上是生活随笔為你收集整理的native react 变颜色 点击_在React Native中按下更改按钮样式(Change button style on press in React Native)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 冷藏温度范围_食品冷藏冷冻温度要求与管理
- 下一篇: oracle自增的两种办法,ORACLE