Android入门之时间日期控件
2023-03-14 10:16:20 时间
效果图:
MainActivity.java
package com.jkxqj.helloandroid; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.DatePicker; public class MainActivity extends Activity { private DatePicker datePicker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); datePicker = (DatePicker)findViewById(R.id.firstDatePicker); datePicker.updateDate(2013, 8, 23); } class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { int y = datePicker.getYear(); int m = datePicker.getMonth(); int d = datePicker.getDayOfMonth(); System.out.println("y:" + y + ",m" + m + ",d:" + d); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <AnalogClock android:id="@+id/clock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="64dp" /> <DatePicker android:id="@+id/firstDatePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/clock" android:layout_centerHorizontal="true" android:layout_marginTop="17dp" /> </RelativeLayout>
相关文章
- 小程序技术生态,工业互联网平台生态打造利器
- 智能电视如何帮助电视行业走出困境?
- 微信小程序模板消息接口下线了,不用慌,调用统一服务消息接口来实现相同功能
- 这场刷屏的微信公开课,腾讯同传也“在场”
- 直播预约:低代码架构设计与思考
- 选对工具,一举搭上工业互联网发展快车
- Typer 构建命令行应用
- 小程序快速搭建生态,助力智能电视发展新思路
- AI生成新春祝福海报,AIGC从“炫技”走向日常
- AirServer2023免费手机投屏电脑软件使用教程
- 2023最新Mac电脑释放内存空间教程方法
- WPF的APP生命周期以及全局异常捕获
- 不背锅运维:一文搞清楚应用发布到k8s集群的基本流程
- 谷歌马甲包上架
- CleanMyMac4.12.3最新版本下载更新
- 微信公众号x低代码,微搭公众号应用开发快速上手教程
- IP归属地的应用场景有哪些?
- 云流化助力展厅播放3D应用内容,如何实现便捷操控?
- 腾讯 PAG 动效方案 2022 回顾
- 好的架构不是设计出来的,而是演进出来的~