TextClock的基本使用
TextClock是在Android 4.2(API 17)后推出的用来替代DigitalClock的一个控件!
TextClock可以以字符串格式显示当前的日期和时间,因此推荐在Android 4.2以后使用TextClock。
这个控件推荐在24进制的android系统中使用,TextClock提供了两种不同的格式, 一种是在24进制中显示时间和日期,另一种是在12进制中显示时间和日期。大部分人喜欢默认的设置。
可以通过调用:TextClock提供的is24HourModeEnabled()方法来查看,系统是否在使用24进制时间显示! 在24进制模式中:
- 如果没获取时间,首先通过getFormat24Hour()返回值;
- 获取失败则通过getFormat12Hour()获取返回值;
- 以上都获取失败则使用默认;
另外他给我们提供了下面这些方法,对应的还有get方法:
| Attribute Name | Related Method | Description |
|---|---|---|
| android:format12Hour | setFormat12Hour(CharSequence) | 设置12时制的格式 |
| android:format24Hour | setFormat24Hour(CharSequence) | 设置24时制的格式 |
| android:timeZone | setTimeZone(String) | 设置时区 |
其实更多的时间我们是花在时间形式定义上,就是里面这个CharSequence! 这里提供下常用的写法以及结果:
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="MM/dd/yy h:mmaa"/> <TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="MMM dd, yyyy h:mmaa"/> <TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="MMMM dd, yyyy h:mmaa"/> <TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="E, MMMM dd, yyyy h:mmaa"/> <TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="EEEE, MMMM dd, yyyy h:mmaa"/> <TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format12Hour="Noteworthy day: 'M/d/yy"/>
运行结果:

PS:另外minsdk 要大于或者等于17哦!
1、布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_height="match_parent"android:layout_width="match_parent"><TextClockandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:format24Hour="当前日期是yyyy年MMMMdd ,今天是EEEE ,当前时间是aa h:mm"/></LinearLayout>
package lpc.com.drawlayoutdemo1;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;publicclassMainActivityextendsAppCompatActivity{@Overrideprotectedvoid onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}

TextClock的基本使用的更多相关文章
- DigitalClock的替代者TextClock
DigitalClock在API 17(Android4.2)中就被官方定义为过时的方法,很奇怪为什么现在很多的网上的帖子都介绍DigitalClock方法的使用(已经过时),如果你想让自己的应用在高 ...
- Android学习笔记(20):时钟(AnalogClock和TextClock)和计时器(Chronometer)
时钟文本TextClock继承自TextView.是用于显示当前时间的文本框. TextClock支持的XML属性和相关方法 XML属性 相关方法 说明 android:format12Hour se ...
- Android零基础入门第59节:AnalogClock、DigitalClock和TextClock时钟组件
原文:Android零基础入门第59节:AnalogClock.DigitalClock和TextClock时钟组件 在前面一期,我们学习了DatePicker和TimePicker,在实际开发中其不 ...
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- Android控件 之 TextClock & AnalogClock(模拟时钟)
TextClock •简介 关于时间的文本显示,Android 提供了 DigitalClock 和 TextClock. DigitalClock是Android第1版本发布,功能很简单,只显示时间 ...
- Android开发自学笔记(Android Studio)—4.2TextView及其子类
一.引言 TextView是我们最常用的一个控件了,它类似于C# Winform程序中的Lable,Java Swing编程中的JLable,不过相对功能更强大些,但从功能上看,它其实就是个文字编辑器 ...
- 疯狂Android讲义 - 学习笔记(二)
Android应用的用户界面编程 2.1 界面编程与视图(View)组件 Android应用的绝大部分UI组件放在android.widget.android.view包及其子包中,所有UI组件都继承 ...
- TextView及其子类
1.TextView控件(TextView是EditView.Button等类的父类) <1>android:id 给当前控件定义了一个唯一标识符 <2>android:l ...
- Android学习笔记⑤——UI组件的学习TextView相关
TextView是一个强大的视图组件,直接继承了View,同时也派生出了很多子类,TextView其作用说白了就是在布局中显示文本,有点像Swing编程中的JLabel标签,但是他比JLabel强大的 ...
随机推荐
- Struts2:国际化
链接:[Java:国际化] src下有国际化资源文件:lan.propertieslan_zh_CN.properties 中文系统系统默认使用zh_CN文件,没有的话使用基本文件lan.proper ...
- MVC执行过程
HttpRuntime中的PR方法1,封装HttpContext2,获取HttpApplication 主要做3件事a,执行本事件时主要调用Init将Global编译得到类型,b,确保Appstart ...
- Visual C++2012中CMFCPropertySheet的用法
看到了一个例子(NewControls),该例子中使用了按钮图片等特效(哈哈,个人觉得挺高端),但是仔细看它的工程,没有xxxDlg.cpp就觉得奇诡了,难道不是基于对话框完成的?最终查阅居然是这样的 ...
- 基础篇-struts2的搭建
.---恢复内容开始--- struts的官网是英文版的,不懂怎么下载的话可以跟着我的步骤来做, 首先去struts的官网http://apache.org/下载struts的报jar类包. 往下拉到 ...
- shell命令快捷键
在shell命令终端中,Ctrl+n相当于方向向下的方向键,Ctrl+p相当于方向向上的方向键. 在命令终端中通过它们或者方向键可以实现对历史命令的快速查找.这也是快速输入命令的技巧. 在命令 ...
- js错误:TypeError $(...) is null
转载自:http://www.phpernote.com/jquery/851.html:
- MAXIMO-数据库配置属性数据类型解释
ALN: 字母数字字符,混合大小写,最大长度取决于数据库 Oracle = 4000 个字符 Sql Server = 8000 个字符 DB2 = 32672 个 ...
- linux 下 TeXmacs 作 Mathematica 10 的前端
TeXmacs可以作很多种数学软件的前端,比如maxima,octave,R等.甚至还可以作mathematica的前端.TeXmacs的mathematica 插件比较老,默认条件下无法运行math ...
- PS 使用首记 修改png图片的颜色
ps打开png图片文件 改颜色 1.魔棒工具,选择图片中的圆圈或方框,双击,选中,出现蚂蚁线. 2.右侧调好颜色 3.alt+delete颜色就改成功了.保存ok. 吸管工具,吸到颜色,存到色板.需要 ...
- EUI HSlider 实现音量控制
一 HSlider使用 直接拖动到exml上,并赋值默认皮肤 <?xml version="1.0" encoding="utf-8"?> < ...