当前位置:网站首页>4、 Button component
4、 Button component
2022-06-22 07:26:00 【Running water I love】
Button Components
A simple button
_onPressButton() {
Alert.alert('You tapped the button!')
}
<Button
onPress={
this._onPressButton}
title="OK!"
color="#841584"
/>
Touchable Series components #
The style of this component is fixed . So if its appearance doesn't match your design , Then you need to use TouchableOpacity or TouchableNativeFeedback Component to customize the buttons you need , Video tutorial How to make a button Describes the complete process . Or you can be in github.com Search on website ‘react native button’ Take a look at the works of others in the community .
Which components are used , It depends on what kind of visual feedback you want to give users :
- Generally speaking , You can use TouchableHighlight To make buttons or links . Note that the background of this component will darken when the user's finger is pressed .
- stay Android You can also use TouchableNativeFeedback, It will create a visual effect similar to ink ripples when the user's finger presses .
- TouchableOpacity It reduces the transparency of the button when the user presses it with his finger , Without changing the color of the background .
- If you want to process click events without any visual feedback , You need to use TouchableWithoutFeedback.
In some scenarios, you may need to detect whether the user has made a long press operation . You can use... In any of the components listed above onLongPress Property to implement .
class Buttonbasics extends Component {
_onPressButton() {
Alert.alert('You tapped the button!');
}
_onLongPressButton() {
Alert.alert('You long-pressed the button!');
}
render() {
return (
<View style={
styles.container}>
<TouchableHighlight onPress={
this._onPressButton} underlayColor="white">
<View style={
styles.button}>
<Text style={
styles.buttonText}>TouchableHighlight</Text>
</View>
</TouchableHighlight>
<TouchableOpacity onPress={
this._onPressButton}>
<View style={
styles.button}>
<Text style={
styles.buttonText}>TouchableOpacity</Text>
</View>
</TouchableOpacity>
<TouchableNativeFeedback
onPress={
this._onPressButton}
background={
Platform.OS === 'android'
? TouchableNativeFeedback.SelectableBackground()
: ''
}>
<View style={
styles.button}>
<Text style={
styles.buttonText}>TouchableNativeFeedback</Text>
</View>
</TouchableNativeFeedback>
<TouchableWithoutFeedback onPress={
this._onPressButton}>
<View style={
styles.button}>
<Text style={
styles.buttonText}>TouchableWithoutFeedback</Text>
</View>
</TouchableWithoutFeedback>
<TouchableHighlight
onPress={
this._onPressButton}
onLongPress={
this._onLongPressButton}
underlayColor="white"
>
<View style={
styles.button}>
<Text style={
styles.buttonText}>Touchable with Long Press</Text>
</View>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
paddingTop: 60,
alignItems: 'center',
},
button: {
marginBottom: 30,
width: 260,
alignItems: 'center',
backgroundColor: '#2196F3',
},
buttonText: {
textAlign: 'center',
padding: 20,
color: 'white',
},
});
export default Buttonbasics;
边栏推荐
- 微信小游戏(五)
- Taobao store backup one store upload to multiple stores precautions
- Detailed explanation of capturing the whole store treasure and uploading it to multiple stores
- Notes on advanced combinatorics -- Conclusion
- [usecols parameter of pd.read\u excel ((), list error reason]
- Use of the thrust Library in CUDA
- Self attention (notes, for personal use)
- An image is worth 16x16 words: translators for image recognition at scale
- Site pre cache code
- Canoe learning notes (6) diagram of logging block data recording module
猜你喜欢

RT-Thread临界段的保护

Up sampling and down sampling (notes, for personal use)

Coursera self driving car Part4 motion planning finalproject principle and key code analysis

飞桨框架v2.3发布高可复用算子库PHI:重构开发范式,降本增效

Choco usage notes -- how to set the default package installation location of choco

Résumé semestriel du programmeur de 33 ans

微信小游戏(四)

How to upload Taobao tmall products with one click

Parameter curve notes of coursera self driving car Part4 motion planning

Backup the method of uploading babies in Taobao stores to multiple stores
随机推荐
Matlab用深度学习循环神经网络RNN长短期记忆LSTM进行波形时间序列数据预测
Coursera self driving car Part4 motion planning finalproject principle and key code analysis
Backup the method of uploading babies in Taobao stores to multiple stores
死链对网站的影响
微信小程序伪装页面(定时改变页面内容)
RFID仓储管理系统解决方案实施可视化流程
Typescript & explain in, keyof, extensions, index signature, record and typeof in detail (updated from time to time)
antd——a-upload-dragger拖拽上传组件——基础积累
How to authorize a picture in a store to another store? What are the methods of unauthorized replication
Mid year summary of 33 year old programmer
How to view cookies in Chrome browser
Taobao assistant can not be used. How to export the baby in the warehouse to backup the data package
Introduction and use of cookies
《百度搜索引擎网页质量白皮书》指导网站建设及优化
Access to control objects in JS
微信小程序服务商下子商户支付下单接口
Site pre cache code
What if the finder fails to respond continuously? Finder unresponsive solution tutorial
A simple examination system based on C language
Chromedriver所有版本下載