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

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

简介:

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

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

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

实例:

9a5e707b8532f765575bc7bcfe874f66.gif

基本设置方法:

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程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值