• TextClock的基本使用


    0、介绍

    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 NameRelated MethodDescription
    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哦!


    PS:另外minsdk 要大于或者等于17哦!
     

    1、布局

    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:orientation="vertical"
    3. android:layout_height="match_parent"
    4. android:layout_width="match_parent">
    5. <TextClock
    6. android:layout_width="wrap_content"
    7. android:layout_height="wrap_content"
    8. android:format24Hour="当前日期是yyyy年MMMMdd ,今天是EEEE ,当前时间是aa h:mm"/>
    9. </LinearLayout>
     
    2、java文件
    1. package lpc.com.drawlayoutdemo1;
    2. import android.os.Bundle;
    3. import android.support.v7.app.AppCompatActivity;
    4. publicclassMainActivityextendsAppCompatActivity{
    5. @Override
    6. protectedvoid onCreate(Bundle savedInstanceState){
    7. super.onCreate(savedInstanceState);
    8. setContentView(R.layout.activity_main);
    9. }
    10. }
    3、效果





  • 相关阅读:
    Foxit 出mac 版本啦
    mac 上的latex (有很多链接,侵权请通知,一定删除)
    集合转数组
    select2搜索框查询加遍历
    下拉框回显
    柱状堆积图Echarts
    echarts X轴数据显示不全问题
    Map静态键值对
    如何配置pl/sql (本地客户端)连接远程oracle服务器
    自定义验证jquery.validate
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/5310935.html
Copyright © 2020-2023  润新知