码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-06-04 22:55:25      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:android

CalendarView简介

CalendarView用于显示和选择日期,如果希望监听事件的改变可以用setOnDateChangeListener()方法。

CalendarView属性介绍

技术分享

代码示例

package peng.liu.test;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.ViewSwitcher;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MainActivity extends Activity {
    CalendarView calendarView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        calendarView = (CalendarView) findViewById(R.id.calendarView);
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(CalendarView calendarView, int i, int i2, int i3) {
                Toast.makeText(MainActivity.this,"您的生日是"+i+"年"+i2+"月"+i3+"日",Toast.LENGTH_LONG).show();
            }
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity"
    android:orientation="vertical"
        >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="选择您的生日"/>
    <CalendarView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/calendarView"
        android:firstDayOfWeek="3"
        android:shownWeekCount="4"
        android:selectedWeekBackgroundColor="#aff"
        android:focusedMonthDateColor="#f00"
        android:weekSeparatorLineColor="#ff0"
        android:unfocusedMonthDateColor="#f9f"
        />
</LinearLayout>

效果图

技术分享

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

标签:android

原文地址:http://blog.csdn.net/lpjishu/article/details/46365315

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!