我希望我的应用程序中的按钮样式在按下时更改.做这个的最好方式是什么?
使用TouchableHighlight
.
这是一个例子:
'use strict'; import React, { Component, StyleSheet, PropTypes, View, Text, TouchableHighlight } from "react-native"; export default class Home extends Component { constructor(props) { super(props); this.state = { pressStatus: false }; } _onHideUnderlay() { this.setState({ pressStatus: false }); } _onShowUnderlay() { this.setState({ pressStatus: true }); } render() { return (); } } Home.propTypes = { text: PropTypes.string.isRequired }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF" }, welcome: { fontSize: 20, textAlign: "center", margin: 10, color: "#000066" }, welcomePress: { fontSize: 20, textAlign: "center", margin: 10, color: "#ffffff" }, button: { borderColor: "#000066", borderWidth: 1, borderRadius: 10 }, buttonPress: { borderColor: "#000066", backgroundColor: "#000066", borderWidth: 1, borderRadius: 10 } }); {this.props.text}
使用道具:
underlayColor
https://facebook.github.io/react-native/docs/touchablehighlight.html