热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

Android学习教程之日历控件使用(7)

这篇文章主要为大家详细介绍了Android学习教程之日历控件操作代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Android日历控件的使用方法,供大家参考,具体内容如下

MainActivity.java代码:

package siso.timessquare;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
  private Button btntimesSquare;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btntimesSquare=(Button)findViewById(R.id.btntimesSquare);
    btntimesSquare.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,SampleTimesSquareActivity.class);
        //直接启动一个Activity
        startActivity(intent);
      }
    });
  }
}

SampleTimesSquareActivity.java代码:

package siso.timessquare;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;

import siso.datelibrary.CalendarCellDecorator;
import siso.datelibrary.CalendarPickerView;
import siso.datelibrary.DefaultDayViewAdapter;

import static android.widget.Toast.LENGTH_SHORT;

public class SampleTimesSquareActivity extends Activity {
  private static final String TAG = "SampleTimesSquareActivi";
  private CalendarPickerView calendar;
  private AlertDialog theDialog;
  private CalendarPickerView dialogView;
  private final Set

SampleDayViewAdapter.java代码:

package siso.timessquare;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import siso.datelibrary.CalendarCellView;
import siso.datelibrary.DayViewAdapter;

public class SampleDayViewAdapter implements DayViewAdapter {
 @Override
 public void makeCellView(CalendarCellView parent) {
   View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.day_view_custom, null);
   parent.addView(layout);
   parent.setDayOfMonthTextView((TextView) layout.findViewById(R.id.day_view));
 }
}

SampleDecorator.java代码:

package siso.timessquare;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import java.util.Date;
import siso.datelibrary.CalendarCellDecorator;
import siso.datelibrary.CalendarCellView;

public class SampleDecorator implements CalendarCellDecorator {
 @Override
 public void decorate(CalendarCellView cellView, Date date) {
  String dateString = Integer.toString(date.getDate());
  SpannableString string = new SpannableString(dateString + "\ntitle");
  string.setSpan(new RelativeSizeSpan(0.5f), 0, dateString.length(),
    Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
  cellView.getDayOfMonthTextView().setText(string);
 }
}

activity_main.xml内容:

<&#63;xml version="1.0" encoding="utf-8"&#63;>


  

Module App下build.gradle内容:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.1"

  defaultConfig {
    applicationId "siso.timessquare"
    minSdkVersion 22
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.0.1'
  compile project(path: ':datelibrary')
}

Module datelibrary下build.gradle内容:

apply plugin: 'com.android.library'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.1"

  defaultConfig {
    minSdkVersion 22
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.0.1'
}

activity_sample_times_square.xml:

<&#63;xml version="1.0" encoding="utf-8"&#63;>




day_view_custom.xml

<&#63;xml version="1.0" encoding="utf-8"&#63;>


  

  


dialog.xml


dialog_customized.xml:


sample_calendar_picker.xml

<&#63;xml version="1.0" encoding="utf-8"&#63;>


 

  

   

资源结构如图:

strings.xml


 Timessquare
 Done
 Customized
 Decorator
 Hebrew
 Arabic
 Custom View
 Dialog
 DisplayOnly
 Range
 Multi
 Single


运行结果如图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
author-avatar
专情与你2602899315
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有