Android開發(fā)之日歷CalendarView用法示例
本文實(shí)例講述了Android開發(fā)之日歷CalendarView用法。分享給大家供大家參考,具體如下:
簡(jiǎn)介:
1.CalendarView是安卓自帶的一個(gè)日歷控件
2.在主活動(dòng)中 通過(guò)設(shè)置setOnDataChangeListener() 來(lái)為其添加監(jiān)聽事件
可在其中獲得 洪湖所選擇的年月日的 詳細(xì)信息
實(shí)例:

基本設(shè)置方法:
1. 日歷的整體背景顏色 android:selectedWeekBackgroundColor="#aff"
2. 月份選擇部分的背景色 android:focusedMonthDateColor="#f00"
3. 顯示星期的背景色 android:weekSeparatorLineColor="#ff0"
4. 被選中的日期的背景色 android:unfocusedMonthDateColor="#f9f"
這里給出它的布局文件中的調(diào)用與配置:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
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"/>
<!--1.設(shè)置以星期二為每周第一天-->
<!--2.設(shè)置該組件總共顯示四個(gè)星期-->
<!--3.并對(duì)該組件的星期盡心了定制-->
<CalendarView
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">
</CalendarView>
</LinearLayout>
在主活動(dòng)中,為其添加監(jiān)聽事件后
可以通過(guò) day month dayOfMonth 來(lái)獲得用戶選擇的日期的具體信息:
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 監(jiān)聽事件
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講義。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android 一個(gè)日歷控件的實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)自定義日歷
- android 開發(fā)教程之日歷項(xiàng)目實(shí)踐(一)
- Android自定義控件實(shí)現(xiàn)可多選課程日歷CalendarView
- android 開發(fā)教程之日歷項(xiàng)目實(shí)踐(三)
- android 開發(fā)教程之日歷項(xiàng)目實(shí)踐(二)
- Android可簽到日歷控件的實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)日歷控件示例代碼
- Android 仿日歷翻頁(yè)、仿htc時(shí)鐘翻頁(yè)、數(shù)字翻頁(yè)切換效果
- Android?Studio簡(jiǎn)單實(shí)現(xiàn)自定義日歷
相關(guān)文章
Android自定義View實(shí)現(xiàn)時(shí)鐘效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)時(shí)鐘效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
使用Thumbnails實(shí)現(xiàn)圖片指定大小壓縮
這篇文章主要為大家詳細(xì)介紹了使用Thumbnails實(shí)現(xiàn)圖片指定大小壓縮,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
Android開發(fā)之?dāng)?shù)據(jù)的存儲(chǔ)方式詳解
本篇文章主要介紹了Android開發(fā)之?dāng)?shù)據(jù)的存儲(chǔ)方式,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。2016-11-11
Android中毛玻璃效果的兩種實(shí)現(xiàn)代碼
這篇文章主要介紹了Android中毛玻璃效果的兩種實(shí)現(xiàn)代碼,第一種是使用JAVA算法FastBlur實(shí)現(xiàn),第二種是使用Android自帶類RenderScript 實(shí)現(xiàn),本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2024-08-08

