1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > android++日历示例 Android开发之日历CalendarView用法示例

android++日历示例 Android开发之日历CalendarView用法示例

时间:2023-05-26 18:45:00

相关推荐

android++日历示例 Android开发之日历CalendarView用法示例

本文实例讲述了android开发之日历calendarview用法。分享给大家供大家参考,具体如下:

简介:

1.calendarview是安卓自带的一个日历控件

2.在主活动中 通过设置setondatachangelistener() 来为其添加监听事件

可在其中获得 洪湖所选择的年月日的 详细信息

实例:

基本设置方法:

1. 日历的整体背景颜色 android:selectedweekbackgroundcolor="#aff"

2. 月份选择部分的背景色 android:focusedmonthdatecolor="#f00"

3. 显示星期的背景色 android:weekseparatorlinecolor="#ff0"

4. 被选中的日期的背景色 android:unfocusedmonthdatecolor="#f9f"

这里给出它的布局文件中的调用与配置:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical">

android:text="please choose your birthday :"

android:gravity="center"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textsize="15dp"

android:typeface="monospace"/>

android:id="@+id/calenderview"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:firstdayofweek="3"

android:shownweekcount="4"

android:selectedweekbackgroundcolor="#aff"

android:focusedmonthdatecolor="#f00"

android:weekseparatorlinecolor="#ff0"

android:unfocusedmonthdatecolor="#f9f">

在主活动中,为其添加监听事件后

可以通过 day month dayofmonth 来获得用户选择的日期的具体信息:

public class mainactivity extends activity {

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_short).show();

}

});

}

}

希望本文所述对大家android程序设计有所帮助。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。