日历视图(CalendarView)

日历视图(Calendarview)

常用属性:

android:selectedWeekBackgroundColor(设置被选中周的背景颜色)

android:showWeekNumber(设置是否显示第几周)

android:unfocusedMonthDateColor(设置没有焦点的月份的日期文字的颜色)

android:weekDaytextAppearance(设置星期几的文字样式)

android:weekNumberColor(设置显示周编号的颜色)

android:weekSeparatorLineColor(设置周分割线的颜色)

监听方法:setOnDatChangeListener

监听器:CalendarView.OnDateChangeListener

下面我们直接看代码:

1.Activity

//日历视图
public class CalendarViewActivity extends Activity {

    private Context context;
    private CalendarView calendarView;
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar_view);
        
        context = this;
        calendarView = (CalendarView)findViewById(R.id.calendarViewId);
        
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            public void onSelectedDayChange(CalendarView view, int year, int month,
                    int dayOfMonth) {
                String content = year+"-"+(month+1)+"-"+dayOfMonth;
                Toast.makeText(context, "你选择了:\n"+content, Toast.LENGTH_SHORT).show();
            }
        });
    }
    
}

2.xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >
<!-- 日历视图 -->
    <CalendarView
        android:id="@+id/calendarViewId"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

3.效果显示图

转载于:https://www.cnblogs.com/wuziyue/p/5470718.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值