zoukankan      html  css  js  c++  java
  • DatePickerAndroid用法

    一、代码
    /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; import React, {Component} from 'react'; import{ StyleSheet, Text, View, DatePickerAndroid, TouchableHighlight, } from 'react-native'; //简单封装一个组件 class CustomButton extends Component { render() { return ( <TouchableHighlight style={styles.button} underlayColor="#a5a5a5" onPress={this.props.onPress}> <Text style={styles.buttonText}>{this.props.text}</Text> </TouchableHighlight> ); } } export default class App extends Component { constructor(props){ super(props); this.state={ presetDate: new Date(2016, 3, 5), allDate: new Date(2020, 4, 5), simpleText: '选择日期,默认今天', minText: '选择日期,不能比今日再早', maxText: '选择日期,不能比今日再晚', presetText: '选择日期,指定2016/3/5', }; } formateDate(date) { var year = date.getFullYear() ; var month = date.getMonth() +1 ; var day = date.getDate() ; var formatedStr = year + '-' + month +'-' + day ; // console.log('formatedStr: ' + formatedStr ) ; return formatedStr ; } //进行创建时间日期选择器 async showPicker(stateKey, options) { try { var newState = {}; const {action, year, month, day} = await DatePickerAndroid.open(options); if (action === DatePickerAndroid.dismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } else { var date = new Date(year, month, day); newState[stateKey + 'Text'] = this.formateDate(date); newState[stateKey + 'Date'] = date; } this.setState(newState); } catch ({code, message}) { console.warn(`Error in example '${stateKey}': `, message); } } render() { return ( <View> <Text style={styles.welcome}> 日期选择器组件实例 </Text> <TouchableHighlight style={styles.button} underlayColor="#a5a5a5" onPress={this.showPicker.bind(this, 'simple',{date: this.state.simpleDate})}> <Text style={styles.buttonText}>点击弹出基本日期选择器</Text> </TouchableHighlight> <CustomButton text={this.state.presetText} onPress={this.showPicker.bind(this, 'preset', {date: this.state.presetDate})}/> <CustomButton text={this.state.minText} onPress={this.showPicker.bind(this, 'min', {date: this.state.minDate,minDate:new Date()})}/> <CustomButton text={this.state.maxText} onPress={this.showPicker.bind(this, 'max', {date: this.state.maxDate,maxDate:new Date()})}/> </View> ); } } const styles = StyleSheet.create({ welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, button: { margin:5, backgroundColor: 'white', padding: 15, borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: '#cdcdcd', } });
    二、效果图
     
    点关注各类It学习资源免费送+V 1153553800
  • 相关阅读:
    【spring】基于AspectJ的AOP
    【matlab】stanford线性回归,logistic regression 实验
    【Python】列表、字典和元组的排序
    PHP 二叉树的深度优先与广度优先遍历
    PHP 定义栈结构,实现min函数,获取栈最小元素,要求时间复杂度为O(1)
    PHP 短连接生成
    一条SQL查询访问记录表(visit_log)中某个类目(catalog_id)的访问量(visit)排前两名的记录行
    利用 p, 1p 随机数发生器知道等概率发生器
    PHP 将二叉查找树转换为双向链表,要求不能创建新节点,只能调节节点指针
    PHP 求最大递增子序列长度
  • 原文地址:https://www.cnblogs.com/binary1010/p/8425503.html
Copyright © 2011-2022 走看看