日期视图与日期Android上的自定义背景

时间:2014-12-22 10:21:26

标签: android

我希望不同日期的android日历视图有不同的颜色,但搜索了很多后我没有找到一种方法来改变我需要的日期背景颜色。任何人都可以帮助我,例如见下面的img。enter image description here

我想要这种类型的观点。

我尝试了日历类的android。正在打开日历,但我无法找到为该日历视图添加颜色的方法。

我的代码就是下面的

公共类ClaenderViewfragment扩展了Activity {

CalendarView calendar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

   setContentView(R.layout.calenderview);


   initializeCalendar();
}


@SuppressLint("NewApi")
public void initializeCalendar() {
        calendar = (CalendarView) findViewById(R.id.calendar);

        // sets whether to show the week number.
        calendar.setShowWeekNumber(false);

        // sets the first day of week according to Calendar.
        // here we set Monday as the first day of the Calendar
        calendar.setFirstDayOfWeek(2);

        //The background color for the selected week.
      calendar.setSelectedWeekBackgroundColor(getResources().getColor(R.color.transparent));

  //sets the color for the dates of an unfocused month.
       calendar.setUnfocusedMonthDateColor(getResources().getColor(R.color.transparent));

        //sets the color for the separator line between weeks.
       calendar.setWeekSeparatorLineColor(getResources().getColor(R.color.transparent));

        //sets the color for the vertical bar shown at the beginning and at the end of the selected date.
       calendar.setSelectedDateVerticalBar(R.color.transparent);

        //sets the listener to be notified upon selected date change.
        calendar.setOnDateChangeListener(new OnDateChangeListener() {
                       //show the selected date as a toast
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
                Toast.makeText(getApplicationContext(), day + "/" +( month+1)+ "/" + year, Toast.LENGTH_LONG).show();
            }
        });

            }

}