react native Switch使用详解
来源:互联网 发布:入门吉他推荐知乎 编辑:程序博客网 时间:2024/06/05 14:46
Switch:开关控件
主要属性:
value:是否打开。默认为false
disabled:是否禁用 默认false
onTintColor:打开时背景色
thumbTintColor:圆形按钮的背景颜色
tintColor:关闭时的边框颜色(iOS)或者背景颜色(Android)。
onValueChange:value值发生变化时的回调,参数为当前Switch的值。提示:如果想要切换Switch,必须改变value值,否则Switch保持不变。
Demo:
import React, {Component} from 'react';import { StyleSheet, View, Switch, Text, Button,} from 'react-native';export default class SwitchDemo extends Component { state = { value: false, disabled: false, changeTxt:'切换Switch', } render() { return ( <View style={{flex:1}}> <View style={{flexDirection:'row',paddingLeft:20}}> <Button title={this.state.value?'关闭':'打开'} onPress={()=>{this.setState({value:!this.state.value});}}></Button> <Switch style={{marginLeft:20}} value={this.state.value} onTintColor='red' tintColor='blue' thumbTintColor='black'/> </View> <View style={{flexDirection:'row',paddingLeft:20,marginTop:20}}> <Button title={this.state.disabled?'启用':'禁用'} onPress={()=>{this.setState({disabled:!this.state.disabled});}}></Button> <Switch style={{marginLeft:20}} value={true} disabled={this.state.disabled}/> </View> <View style={{flexDirection:'row',paddingLeft:20,marginTop:20}}> <Text>{this.state.changeTxt}</Text> <Switch value={this.state.value} onValueChange={(value)=>{ this.setState({ value:value, changeTxt:value?'switch 打开了':'switch 关闭了' }); }}/> </View> </View> ); }}
效果图
github下载地址
1 0
- react native Switch使用详解
- react native ActivityIndicator使用详解
- react native Button 使用详解
- react native Text 使用详解
- react native ScrollView 使用详解
- react native FlatList 使用详解
- react native SectionList 使用详解
- react native TextInput 使用详解
- react native Slider 使用详解
- react native StatusBar 使用详解
- react native DatePickerIOS 使用详解
- react native DrawerLayoutAndroid 使用详解
- react native Image 使用详解
- react native Modal 使用详解
- react native Picker 使用详解
- react native ProgressBarAndroid 使用详解
- react native RefreshControl 使用详解
- react native SegmentedControlIOS 使用详解
- JavaTM Platform Standard Edition 6 API 规范
- 2017系统架构设计师的通过人数与通过率探秘
- 【编程题目】Pq.8--求单向链表的倒数第k个节点(关于代码鲁棒性的探讨)
- 机器学习&深度学习视频资料大汇总
- FFmpeg总结(七)AV系列结构体之AVIOContext
- react native Switch使用详解
- http://blog.sina.com.cn/s/blog_a74f39a201018jal.html
- iOS中的URL Scheme
- fftw3-3.5 Windows 安装
- SpringBoot创建web工程
- github的使用总结
- <Qt>事件的accept()与ignore()的传递
- Linux下安装配置JDK
- iOS 全屏截图