gpt4 book ai didi

javascript - 单击使用 react native 时如何更改图像和文本颜色?

转载 作者:技术小花猫 更新时间:2023-10-29 10:33:05 26 4
gpt4 key购买 nike

我正在使用 TouchableHighlight,但我只能使用 underlayColor 更改背景颜色。但是如何更改其他内容呢?

最佳答案

'use strict';

var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight
} = React;

var colors = ['#ddd', '#efefef', 'red', '#666', 'rgba(0,0,0,.1)', '#ededed'];
var backgroundcolors = ['green', 'black', 'orange', 'blue', 'purple', 'pink'];

var SampleApp = React.createClass({

getInitialState() {
return {
color: 'orange',
backgroundColor: 'rgba(0,0,0,.1)'
}
},

_changeStyle() {
var color = colors[Math.floor(Math.random()*colors.length)];
var backgroundColor = backgroundcolors[Math.floor(Math.random()*backgroundcolors.length)];
this.setState({
color: color,
backgroundColor: backgroundColor
})
},

render: function() {
return (
<View style={styles.container}>
<TouchableHighlight
onPress={ () => this._changeStyle() }
style={{ backgroundColor: this.state.backgroundColor, height: 60, flexDirection: 'row', alignItems:'center', justifyContent: 'center' }}>
<Text style={{ fontSize: 22, color: this.state.color }}>CHANGE COLOR</Text>
</TouchableHighlight>

<TouchableHighlight style={{ backgroundColor: 'red', height: 60, flexDirection: 'row', alignItems:'center', justifyContent: 'center' }}>
<Text style={{ color: 'white', fontSize:22 }} >Click Me</Text>
</TouchableHighlight>
</View>
);
}
});

var styles = StyleSheet.create({
container: {
flex: 1,
marginTop:60
}
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);

关于javascript - 单击使用 react native 时如何更改图像和文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34088496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com