日历视图使用

作者: Lee_5566 | 来源:发表于2019-12-18 10:46 被阅读0次
image.png

目录

CalenderView

CalendarView是安卓自带的一个日历控件, 可以使用其开发手机日历的相关功能.

使用例子:

    <CalendarView
      android:id="@+id/calenderView"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

使用接口说明

接口 含义
setOnDataChangeListener() 添加监听事件,获取当前选择的日期
android:selectedWeekBackgroundColor="#aff" 日历的整体背景颜色
android:focusedMonthDateColor="#f00" 月份的背景色
android:weekSeparatorLineColor="#ff0" 星期的背景色
android:unfocusedMonthDateColor="#f9f" 被选中的日期背景色

实战

activity_main.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <CalendarView
        android:id="@+id/calenderView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:selectedWeekBackgroundColor="#aff"
        android:focusedMonthDateColor="#f00"
        android:weekSeparatorLineColor="#ff0"
        android:unfocusedMonthDateColor="#f9f" />


</android.support.constraint.ConstraintLayout>

代码:

package com.example.user.calender;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    CalendarView calendarView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        calendarView = (CalendarView) findViewById(R.id.calenderView);
        //calendarView 监听事件
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange( CalendarView view, int year, int month, int dayOfMonth) {
                //显示用户选择的日期
                Toast.makeText(MainActivity.this,year + "年" + month + "月" + dayOfMonth + "日",Toast.LENGTH_LONG).show();
            }
        });
    }
}

运行效果:


image.png

参考

Android开发之日历CalendarView用法示例

相关文章

  • 日历视图使用

    目录 CalenderView CalendarView是安卓自带的一个日历控件, 可以使用其开发手机日历的相关功...

  • 安卓开源控件库收藏

    日历 日历列表视图https://github.com/traex/CalendarListview 星期视图日历...

  • 滴答清单应该这样用:日历视图

    为什么使用日历视图 日历视图是很多任务管理软件中普遍存在的功能。 它可以从多个角度管理任务的发展情况,以及进行月总...

  • 高仿小米日历

    一款仿miui,仿小米,日历,周日历,月日历,月视图、周视图滑动切换,农历,Andriod Calendar , ...

  • 十五、Android用到的View补充

    首先列出补充的View:CalendarView:日历视图GridView:网格视图SearchView:搜索视图...

  • Flutter自制插件之r_calendar日历插件

    r_calendar ??Flutter日历插件,支持自定义日历,月视图/周视图切换、点击拦截、单选(切换月自动选...

  • 日历-最简单实用的时间管理工具

    日历是一个非常好用的时间管理工具,一般电子日历提供日视图、周视图、月视图和年视图,可以随时对自己做过的事情...

  • 安卓控件大全

    日历 星期视图日历 https://github.com/alamkanak/Android-Week-View ...

  • iOS日历视图

    最近开发需要,所以自己设计了一个日历视图,主要用到了UICollectionView,以及UICalendar和N...

  • 仿小米日历

    仿MIUI日历 一款仿miui日历,月视图,周视图滑动切换,时间从1901-01-01到2099-12-31 支持...

网友评论

    本文标题:日历视图使用

    本文链接:https://www.haomeiwen.com/subject/zzxsnctx.html