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',
}
});
二、效果图
DatePickerAndroid用法的更多相关文章
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
- 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)
vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...
随机推荐
- SQL server 数据库的版本为661,无法打开,此服务器只支持655版及更低版本。不支持降级路径
亲测有效. 解决方案:造成这个错误是因为把本地的SQL Server (MSSQLSERVER)服务给禁止了,而把 SQL Server (SQLEXPRESS)服务给启动了,因为这样子,本来应该在数 ...
- INTRODUCE OF REPRESENTATIVE CPG-CONTROLLED ROBOTS
仿生机器人研究是非常有意思的领域,它不仅从自然界中获取灵感,它也为一些生物的研究提供一个手段和基础,正如下图中所展示的.不论人工智能发展的如何迅速,机械结构始终做为着一个承载的平台,其重要性不可忽略. ...
- Project中最常用的注意点
最近用Project 2013做计划,做工作量的评估,感觉确实牛逼得一塌糊涂.这几天自己试着做一些手工的计算,与Project的结果进行对比,发现学到的很多东西,网上确实很难道到,花了几天的时间研究, ...
- idea 的一些基本的配置
1. 2. 3. http://139.199.89.239:1008/88414687-3b91-4286-89ba-2dc813b107ce 531403098@qq.com R+0oOAb3rx ...
- Spring框架中获取连接池的几种方式
什么是数据库连接池? 数据库连接池是一种关键的有限的昂贵的资源,对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池就是用来解决这些问题而提出的. 数据库连接 ...
- [linux]关于deepin截图软件在KDE桌面下无法使用粘贴的解决方法
-------更新----- 1.其实不如直接关闭klipper启动程序 # rm -rf /usr/share/plasma/plasmoids/org.kde.plasma.clipboard 2 ...
- Nullable object must have a value
有一个linq查询,由inner join改成left join, 对于有空值,就会出现Nullable object must have a value 的错误. 原来的查询: var qry = ...
- 终端的rz命令,覆盖原文件。
不覆盖:rz 覆盖 同名文件:rz -y
- 拯救者R720安装Ubuntu之后无法连接无线网络
安装Ubuntu后无法连接到无线网络 Ubuntu默认关闭了硬件wifi开关,拯救者R720只有软件开关,所以引起了wifi不可用的问题 使用rfkill list all 命令:0:ideapad_ ...
- Spring Cloud分布式微服务云架构
分布式.微服务.云架构 JAVA语言开发.跨平台.高性能.高可用.安全.服务化.模块化.組件化.驱动式开发模式 commonservice eurekaNetflix 云端服务发现,一个基于 REST ...
