官方文档:
https://reactnative.cn/docs/touchablehighlight/#docsNav
代码复制即可使用
代码:
TouchableHighlightDemo.js
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Alert, Button,TouchableHighlight} from 'react-native';
/**
* Flexbox 布局
* https://reactnative.cn/docs/touchablehighlight/#docsNav
*/
export default class TouchableHighlightDemo extends Component {
//渲染数据
render() {
return (
<View style={styles.root}>
<TouchableHighlight onPress={() => this.myOnclick()} underlayColor="#FFCC00">
<Text style={styles.textStyle}>按钮</Text>
</TouchableHighlight>
</View>
);
}
myOnclick = () => {
alert('按钮点击了');