亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開發(fā)之日歷CalendarView用法示例

 更新時(shí)間:2019年03月18日 11:44:13   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之日歷CalendarView用法,簡單分析了日歷CalendarView組件的功能、屬性設(shè)置方法、界面布局、事件監(jiān)聽等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)之日歷CalendarView用法。分享給大家供大家參考,具體如下:

簡介:

1.CalendarView是安卓自帶的一個(gè)日歷控件

2.在主活動(dòng)中 通過設(shè)置setOnDataChangeListener() 來為其添加監(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.并對該組件的星期盡心了定制-->
    <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)聽事件后

可以通過 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 監(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)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論