广告
返回顶部
首页 > 资讯 > 精选 >Android之日期时间选择控件DatePicker和TimePicker实例
  • 766
分享到

Android之日期时间选择控件DatePicker和TimePicker实例

datepickerandroidtimepicker 2023-05-31 03:05:03 766人浏览 八月长安
摘要

这个月根据需求在项目中做了一个时间选择器,虽然没有用到Android原生的时间选择控件,但我羞愧地发现自己竟然从来没有用过这方面控件!趁现在有时间,赶紧查缺补漏,写一篇博客吧。(注:为了便于区分,本文将选择年月日的控件称为日期选择控件,将选

这个月根据需求在项目中做了一个时间选择器,虽然没有用到Android原生的时间选择控件,但我羞愧地发现自己竟然从来没有用过这方面控件!趁现在有时间,赶紧查缺补漏,写一篇博客吧。

(注:为了便于区分,本文将选择年月日的控件称为日期选择控件,将选择时分的控件称为时间选择控件。)

1、创建项目

新建一个项目,MainActivity的布局如下:

<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:id="@+id/activity_main"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  android:padding="10dp"  tools:context="com.lindroid.datetimepickerdemo.MainActivity">  <LinearLayout    android:id="@+id/ll_date"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="horizontal">    <TextView      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="选择日期:"      android:textSize="18sp" />    <TextView      android:id="@+id/tv_date"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:background="#ededed"      android:padding="8dp"      android:textSize="18sp" />  </LinearLayout>  <LinearLayout    android:id="@+id/ll_time"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="5dp"    android:orientation="horizontal">    <TextView      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="选择时间:"      android:textSize="18sp" />    <TextView      android:id="@+id/tv_time"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:background="#ededed"      android:padding="8dp"      android:textSize="18sp" />  </LinearLayout></LinearLayout>

--结束END--

本文标题: Android之日期时间选择控件DatePicker和TimePicker实例

本文链接: https://www.lsjlt.com/news/223106.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作