1.介绍

2.常用属性

3.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <Button
android:id="@+id/button"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> <CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </LinearLayout>

4.java后台

对应的工程名:test26

package com.lucky.test26calendar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.Toast; import java.text.SimpleDateFormat; public class MainActivity extends AppCompatActivity { CalendarView calendarView;
Button button;
String timeStr="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendarView=findViewById(R.id.calendarView);
button=findViewById(R.id.button);
//设置时间显示格式
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //yyyy表示年,MM表示月,dd表示天,HH表示时,mm表示分,ss表示秒
timeStr=simpleDateFormat.format(calendarView.getDate()); //将calendarView获取的时间样式转化为simpleDateFormat所设置的样式
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,timeStr,Toast.LENGTH_SHORT).show();
}
}); calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange( CalendarView view, int year, int month, int dayOfMonth) {
timeStr=year+"-"+month+"-"+dayOfMonth;
}
}); }
}

Android 日历视图(Calendarview)的更多相关文章

  1. Android零基础入门第60节:日历视图CalendarView和定时器Chronometer

    原文:Android零基础入门第60节:日历视图CalendarView和定时器Chronometer 上一期学习了AnalogClock.DigitalClock和TextClock时钟组件,本期继 ...

  2. Android日历视图(CalendarView)讲解-android学习之旅(三十六)

    CalendarView简介 CalendarView用于显示和选择日期,如果希望监听事件的改变可以用setOnDateChangeListener()方法. CalendarView属性介绍 代码示 ...

  3. Android自带CalendarView类实现日历视图

    文章由来:学习一下日历控件的实现,Android3.0以下的版本请查阅其他文章. 本文主要是介绍Android日历视图控件CalendarView相关的内容,然后在后面会给出一个简单的Demo. Ca ...

  4. Android学习笔记(27):日历视图Calendar

    日历视图CalendarView可用于显示和选择日期. 能够调用setOnDateChangedListener()方法绑定事件监听器. 经常使用XML属性和相关方法: XML属性 相关方法 说明 a ...

  5. 日历视图(CalendarView)

    日历视图(Calendarview) 常用属性: android:selectedWeekBackgroundColor(设置被选中周的背景颜色) android:showWeekNumber(设置是 ...

  6. Android——滚动视图(ScrollView)图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟

    xml <?xml version="1.0" encoding="utf-8"?> <!--滚动视图--> <ScrollVie ...

  7. 日历视图(CalendarView)组件的功能和用法

    日历视图(CalendarView)可用于显示和选择日期,用户既可选择一个日期,也可通过触摸来滚动日历.如果希望监控该组件的日历改变,可调用CalendarView的setOnDateChangeLi ...

  8. Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟、图片透明度、滚动和时间选择器

    activity_ui1.xml dth="wrap_content" android:layout_height="wrap_content" android ...

  9. Android列表视图(List View)

    Android列表视图(ListView) ListView是一个显示滚动项列表的示视图组(viewgroup),通过使用适配器(Adapter)把这些列表项自动插入到列表中.适配器比如从一个数组或是 ...

随机推荐

  1. 动画系统II

    [动画系统II] 1.动画混合(animation blending)是把某个时间点的两个或更多的输入姿势结合,产生骨骼的输出姿势.例如,通过混合负伤的及无负伤的步行动画,我们可以生成二者之间不同负伤 ...

  2. Splay树分析

    简述 Splay树是一种二叉查找平衡树,其又名伸展树,缘由是对其进行任意操作,树的内部结构都会发生类似伸张的动作,换言之,其读和写操作都会修改树的结构.Splay树拥有和其它二叉查找平衡树一致的读写时 ...

  3. 编程中&&和||的妙用

    &&符号在编程中表示“和”,也就是数学中的“且”! if(A && B){ } 上面的代表表示A==true并且B==true的情况下就执行花括号里面的代码. 值得注意 ...

  4. 605. Can Place Flowers零一间隔种花

    [抄题]: Suppose you have a long flowerbed in which some of the plots are planted and some are not. How ...

  5. 2014年:Linux和开源的福祸之年

    (1)Heartbleed漏洞 Heartbleed漏洞,是今年开源软件曝出的最大糗事.Heartbleed漏洞是OpenSSL的重大漏洞,这项严重缺陷(CVE-2014-0160)的产生是由于未能在 ...

  6. Makefile 调试

    一.简介 GNU make 提供了若干可以协助调试的内置函数以及命令行选项. 用来调试makefile 的一个最好方法就是加入调试挂钩以及使用具保护的编程技术,让你能够在事情出错时恢复原状. 二.ma ...

  7. 前端基础 之 Bootstrap框架

    浏览目录 Bootstrap介绍 为什么要使用Bootstrap? Bootstrap环境搭建 布局容器 栅格系统 Bootstrap全局样式 一.Bootstrap介绍 Bootstrap是Twit ...

  8. html5之音频、视频(video&audio)

    音频&视频 本篇为本人的学习笔记. 在Html5之前,浏览器对于视频和音频的处理并没有一个标准.因此在网页中看到的视频,都是通过第三插件的方式嵌入的,如:QuickTime.RealPlaye ...

  9. Daubechies Wavelet

    The Daubechies wavelets, based on the work of Ingrid Daubechies, are a family of orthogonal wavelets ...

  10. windows phone制作引导页

    适用于WP7 WP8+ 源码下载撸这里 制作动画gif小软件下载 小技巧 ①图片是纯色背景:将页面设置跟图片背景一样颜色 ②图片是渐变or其他,切图时候:单独切背景(页面设置这个为背景)跟图片里面元素 ...