Android日历只显示年月

款式如下:

public class YearPickerDialog extends DatePickerDialog {public YearPickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {super(context, callBack, year, monthOfYear, dayOfMonth);//        this.setTitle(year + "年" + (monthOfYear + 1) + "月");((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(1).setVisibility(View.GONE);((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);}public YearPickerDialog(Context context, int theme, OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) {super(context, theme, listener, year, monthOfYear, dayOfMonth);//        this.setTitle(year + "年" + (monthOfYear + 1) + "月");((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(1).setVisibility(View.GONE);((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);}@Overridepublic void onDateChanged(DatePicker view, int year, int month, int day) {super.onDateChanged(view, year, month, day);this.setTitle(year + "年" );}
}

Android日历只显示年

款式如下:

public class MonPickerDialog extends DatePickerDialog {public MonPickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {super(context, callBack, year, monthOfYear, dayOfMonth);//        this.setTitle(year + "年");((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);}public MonPickerDialog(Context context, int theme, OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) {super(context, theme, listener, year, monthOfYear, dayOfMonth);//        this.setTitle(year + "年" );((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);}@Overridepublic void onDateChanged(DatePicker view, int year, int month, int day) {super.onDateChanged(view, year, month, day);this.setTitle(year + "年");}
}

关于使用

private void selectMonthTime() {new MonPickerDialog(getActivity(), AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {@Overridepublic void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {calendar.set(Calendar.YEAR, year);calendar.set(Calendar.MONTH, monthOfYear);id_tv_time_month.setText(DateUtil.clanderTodatetime(calendar, "yyyy-MM"));  }}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)).show();}

DateUtils

public class DateUtil {public static Date strToDate(String style, String date) {SimpleDateFormat formatter = new SimpleDateFormat(style);try {return formatter.parse(date);} catch (ParseException e) {e.printStackTrace();return new Date();}}public static String dateToStr(String style, Date date) {SimpleDateFormat formatter = new SimpleDateFormat(style);return formatter.format(date);}public static String clanderTodatetime(Calendar calendar, String style) {SimpleDateFormat formatter = new SimpleDateFormat(style);return formatter.format(calendar.getTime());}public static String DateTotime(long date, String style) {SimpleDateFormat formatter = new SimpleDateFormat(style);return formatter.format(date);}

Android日历只显示年月,只显示年相关推荐

  1. android 修改DatePickerDialog只显示“年月”,去掉“日”显示

    这两天在做一个项目,其中有个需求是让用户填写学业经历,那么只能选择年月,而不能出现日选择.通过在网上查资料,发现原理都是通过获取到Dialog布局中的年月日分别相对应的View,然后将其设置为GONE ...

  2. easyui datebox时间控件如何只显示年月

    easyui datebox控件,只显示年月,不显示年月日 需要的效果图如下: 具体的js代码: <script>$(function(){intiMonthBox('costTime') ...

  3. html只能选择年月,EasyUi日期控件datebox设置,只显示年月,也只能选择年月

    EasyUi日期控件datebox设置,只显示年月,也只能选择年月 1.input 代码 年月 1 2 3 4 5 6 7 8 2.设置只显示年月,只能选持年月: $(function() { $(' ...

  4. easyUI datebox 日期只显示年月及年月日切换的实现 js样式重新渲染加载

    记录一下,最近的做的一个功能,需要在easyUI的日期框datebox 中,只显示年月格式,同时,还需要切换到年月日的格式 第一步:如何显示年月日,默认当前一天 如下代码是:报表日期及时间选择框 报表 ...

  5. Android Google Map 开发指南(一)解决官方demo显示空白只展示google logo问题

    这两天一直在做google map接入前的准备工作 特此在这里将自己在加载官方demo时出现的问题以及详细的接入步骤进行记录,已免后者踩坑 注:项目实际运行时不要使用虚拟机 因为电脑ip和虚拟机ip不 ...

  6. ABAP日期函数(求月末日,第几周,search help 只显示年月) 使用方法实例

    计算两个日期间的工作天数,就是剔除了双休日后的天数.( 待考证) DATE_CONVERT_TO_FACTORYDATE HR_HK_DIFF_BT_2_DATES 根据当前时间如何找到上月的第一天和 ...

  7. 百度地图开发只显示网格不显示地图信息

    这些天公司也没什么事情了,自己就想来玩玩百度地图API,先熟悉一下,废话就不多说了,先将遇到的这个问题描述一下吧!我就是参考了百度官网上的例子,在eclipse中运行了一下,结果只显示网格没有显示地图 ...

  8. 在discuzNT中加入Adsense广告(只在第一楼显示)

    前段时间发布了一篇关于在帖子中adsense插入广告文章http://nt.discuz.net/showtopic-22082.html 但是会在所有的帖子中都插入广告,这样就违反了google中所 ...

  9. 数码管显示1到8c语言,单片机控制八只数码管滚动显示1~8 附PROTEUS软件仿真图

    数码管显示是每一个单片机初学者都必须学的,而单片机驱动数码管的数字循环显示实验,又是单片机基础中的基础,同时也是学好C语言编程的关键,此实验在硬件上可以弄清楚单片机驱动原理和数码管的显示原理,在软件上 ...

最新文章

  1. Elasticsearch 运维实战之1 -- 集群规划
  2. IDEA2021.3无法创建测试类解决方法
  3. 层和 native_React-Native与小程序的底层框架比较
  4. 数据结构 - 字符串 - 最长公共子序列 + 最长公共子字符串 - 动态规划
  5. Hibernate代码生成工具 设计全攻略
  6. 使用U盘安装Windows Server2008
  7. python去重且顺序不变_Python中list去重且保持原顺序不变的方法
  8. ajax跨域问题(php)
  9. linux文件名过长无法删除,不能删除文件,出现“源文件名长度大于系统支持的长度...
  10. 俯视角场景搭配潮流色彩,诠释海报唯美视角
  11. PowerBuilder制作纸牌游戏
  12. 如何让电脑产生和输出特定分贝值的声音
  13. mysql索引失效的常见9种原因详解
  14. 使用three.js模拟城市灯光秀
  15. 作为Gatekeeper,请守好交付质量关口(Quality Gate)
  16. UIQ全方位实现与ActiveSync进行数据交换(转)
  17. 系统学习机器学习之特征工程(三)--多重共线性
  18. 计算机状态oxc0000001,电脑蓝屏代码0x00000001解决方法
  19. ios识别人脸自动拍照_真的逆天?iOS 10相册识别人脸的秘密
  20. 2017 计算机 暑期学校,2017暑期学校

热门文章

  1. 汉语韵律短语切分方法初探
  2. r420服务器安装系统,r420服务器bios设置
  3. 工信部通报下架60款APP:关联有赞、三六零、唯品会等上市公司
  4. 为什么卸载TeamViewer
  5. 天瑞地安科技集团程序员波波告诉你程序员必备开发工具
  6. 项目管理的SDCA环、PDCA环
  7. 大数据可视化,助力行业大数据应用
  8. java单链表快慢指针
  9. html中meta的写法规范,HTML代码meta标签的charset 属性写法及用法
  10. sharding-jdbc(ShardingSphere )、mycat、DRDS 三个分布式数据库中间件的简单介绍(纯理论说明)