android 中的 日历控件
<RelativeLayout 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"
tools:context=".MainActivity" >
<!-- api 11 -->
<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
long getDate(); //获取从1970年,1月1日,0点0分0秒到现在的毫秒数
int getFirstDayOfWeek(); //获取当天是本周的第几天,比如Calendar.Monday为星期一,定义值为2。
long getMaxDate(); //获取CalendarView支持1970年到那天的最大天数
long getMinDate(); //获取CalendarView支持1970年到那天的最小天数
boolean getShowWeekNumber(); //获取是否显示星期号
public void setDate(long date, boolean animate, boolean center); //设置选择日期到1970年的描述
void setDate(long date); //设置选择的日期描述到1970年
void setFirstDayOfWeek(int firstDayOfWeek); //设置本周起始天数
**/
/** android 3.0以上才有 */
CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
calendarView.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
String date = year + "年" + (month+ 1) + "月" + dayOfMonth +"日";
Toast.makeText(MainActivity.this, date, Toast.LENGTH_SHORT).show();
}
});
}
}
当然这个控件时 android 3.0以上才提供的,
如果3.0以下需要用到的话就需要别的 第三方开发的控件了。这里没什么说的,可以自己搜一搜。我这里上传几个(里面有很多实用的自定义日历)。
下载地址:http://download.csdn.net/detail/kongbaidepao/6638669
下载地址里面都是我手机的一些 自定的日历,效果还都挺不错的。
再推荐1个开源项目
https://github.com/square/android-times-square
效果也是很不错的
贴2张效果图