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强大的 ...
随机推荐
- 大规模IP地址黑名单高性能查询实现
嗯……前阵子接了个活儿,需要做一个基于IP地址黑名单的分流网关.刚接到的时候心想iptables不就行了么,没想到一看客户给的IP黑名单规模……我擦……上亿个…… 黑名单到了这个规模,就不得不考虑下优 ...
- double四舍五入,商品金额大小写转换,设置货币的小数位数跟格式输出,进制转化
1:计算double值四舍五入的方法 对小数数值进行四舍五入,首先应该确认保留小数位, 如果数值的小数精度大于保留小数位,那么开始四舍五入计算.四舍五入的方法非常简单,在所有要丢失精度的小数位中加 ...
- 关于Oracle GoldenGate中Extract的checkpoint的理解 转载
什么是checkpoint? 在Oracle 数据库中checkpoint的意思是将内存中的脏数据强制写入到磁盘的事件,其作用是保持内存中的数据与磁盘上的数据一致.SCN是用来描述该事件发生的准确的时 ...
- Struts2基础使用教程:OGNL
取自<JAVAWEB整合开发王者归来> 是一种类似EL的语言,比EL强大的多 能访问对象的方法,例如list.size() 能访问静态属性与静态方法,方法是在类名前.方法前加上@.如@ja ...
- Type.GetType(string)为空
Type type = Type.GetType(scheduleJob.JobType); 时type为空, 导致执行下一步时 MethodInfo method = type.GetMethod( ...
- Spring知识汇总
Spring简介 Spring框架由Rod Johnson开发,2004年发布了Spring框架的第一版.Spring是一个从实际开发中抽取出来的框架,因此它完成了大量开发中的通用步骤,留给开发者的仅 ...
- Android test---SL4A
这里有一个链接http://www.linuxidc.com/Linux/2014-02/96452.htm 详细教程
- 使用 Wireshark 调试 HTTP/2 流量
https://imququ.com/post/http2-traffic-in-wireshark.html
- JS function document.onclick(){}报错Syntax error on token "function", delete this token
JS function document.onclick(){}报错Syntax error on token "function", delete this token func ...
- rabbitMQ学习(五)
topic匹配模式,topic能满足匹配结果就行. 发送端: public class EmitLogTopic { private static final String EXCHANGE_NAME ...