Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android DigitalClock 數位時鐘元件用法實例

編輯:關於 Android 程式設計

本文說明 Android 內建的 DigitalClock 元件怎麼用,重點是:它完全不需要寫 Java 就能顯示時間。

直接在版面檔裡放上去就好

DigitalClock 會自行向系統取得目前時間並即時更新,開發者不必建立物件、也不必自己啟動計時器。只要在使用者想看時間的位置寫入這個標籤即可。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <DigitalClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"/>
</LinearLayout>

何時該選它

適合只需要「純顯示時間」的情境,例如工具面板、計時看板。若你需要自訂時分秒格式、要顯示日期,或想搭配鬧鐘、碼錶樣式,就該改用 TextClock 或自行以 Chronometer、自繪 View 來處理,因為 DigitalClock 的可客製化程度相當有限。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved