Android 0 Basics Section 59th: AnalogClock, DigitalClock, and Textclock clock components

Source: Internet
Author: User
Tags time and date


Original: Android 0 basic Introductory Section 59th: AnalogClock, DigitalClock, and Textclock clock components





In the previous issue, we studied DatePicker and Timepicker, which could not fully satisfy our processing of time and date in actual development.



If you just want to show the time, without user modification, you can use the DigitalClock and AnalogClock clock components, which are very useful and easy to use, with values that can be updated automatically over time.











First, AnalogClock





First come together to learn analogclock components. AnalogClock inherits the view, which can be overridden in the actual development of the OnDraw method.



The XML for AnalogClock has 3 properties, as follows:


    • Android:dial: The table background of the analog clock.

    • Android:hand_hour: Simulates the clock's Table hour.

    • Android:hand_minute: The table minute hand of the analog clock.


You can use the system default, or you can customize the picture resource.






Next, a simple example program is used to learn the use of AnalogClock.



To continue using the Advancedviewsample module of the Widgetsample project, first download a picture of the dial in the drawable directory and then create the Analogclock_ in the app/main/res/layout/directory Layout.xml file, where the following code snippet is populated:


 
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
    <AnalogClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:dial="@drawable/dial"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>


Modify the code inside the mainactivity, load the above defined layout file, and then run the program, you can see the interface effect shown.











Second, DigitalClock





The AnalogClock is an analog clock in a dial format, while the DigitalClock is a digital clock. DigitalClock inherits the TextView, which is itself a text box.



Next, a simple example program is used to learn the use of DigitalClock.



Still using the Advancedviewsample module of the Widgetsample project, create the Digitalclock_layout.xml file in the app/main/res/layout/directory, populated with the following code snippet:


 
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
    <DigitalClock
        android:id="@+id/digitalClock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:textColor="#ff0000"
        android:textSize="30sp" />
</RelativeLayout>


Modify the code inside the mainactivity, load the above defined layout file, and then run the program, you can see the interface effect shown.











Third, Textclock





DigitalClock is obsolete from API 17, it is recommended to use the new component Textclock. Textclock is more powerful, it can not only display the time, but also display the date, and support the custom format.



Textclock provides two different formats, one for displaying time and date in 24, and the other for displaying time and date in 12 binary.



Textclock mainly has the following XML attributes:


    • Android:format12hour: Set the format of the 12 O'Clock system

    • Android:format24hour: Set the format of the 24 o'clock system

    • Android:timezone: Sets the time zone.


The main methods of Textclock are:


    • Getformat12hour (): Returns the time mode in 12 binary mode.

    • Getformat24hour (): Returns the time mode in 24 binary mode.

    • getTimeZone (): Returns the time zone that is in use.

    • Is24hourmodeenabled (): Detects whether the system is currently using 24 binary.

    • Setformat24hour (charsequence format): Sets the 24 o'clock format.

    • Setformat12hour (charsequence format): Sets the 12 o'clock format.

    • Settimezone (String TimeZone): Sets the time zone.


Next, a simple example program is used to learn the use of Textclock.



Still using the Advancedviewsample module of the Widgetsample project, create the Textclock_layout.xml file in the app/main/res/layout/directory, populated with the following code snippet:


 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
    <TextClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        android:format24Hour="yyyy年MM月dd EE\naa HH:mm:ss"
        android:format12Hour="yyyy年MM月dd EE\naa hh:mm:ss"
        android:textStyle="normal"
        android:fontFamily="sans-serif-light"
        android:textSize="26sp"
        tools:targetApi="jelly_bean_mr1"/>
</RelativeLayout>


Where format is the same as the SimpleDateFormat class learned in Java. Android:fontfamily= "Sans-serif-light" is used to set the Android font.



Modify the code inside the mainactivity, load the above defined layout file, and then run the program, you can see the interface effect shown.









Come here today, if you have any questions welcome message to discuss together, also welcome to join the Android 0 Basic introductory Technical discussion group, grow together!



This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if necessary reprint please contact the author authorized, hereby declare!






Past period Summary share:



Android 0 Basics Introduction 1th: Android's past life



Android 0 Basics Section 2nd: Android system Architecture and application components those things



Android 0 Basics Section 3rd: Bring you up to talk about Android development environment



Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick



Android 0 Basics 5th: Use ADT bundles to easily meet the goddess



Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess



Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey



Android 0 Basics 8th: HelloWorld, the starting point for my first trip



Android 0 Basics 9th: Android app, no code can be developed



Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio



Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project



Android 0 Basics 12th: Get familiar with the Android studio interface and start selling



Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool



Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era



Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing



Android 0 Basics Section 16th: Android User Interface Development overview



Android 0 Basics Section 17th: text box TextView



Android 0 Basics Section 18th: Input box EditText



Android 0 Basics Get started section 19th: Buttons button



Android 0 Basics 20th: check box checkbox and radio button radiobutton



Android 0 Basics Section 21st: Switch Components ToggleButton and switch



Android 0 Basics Section 22nd: Image View ImageView



Android 0 Basics Section 23rd: Image button ImageButton and zoom button Zoombutton



Android 0 Basics Section 24th: Customize view simple to use to create your own controls



Android 0 Basics Section 25th: Simple and most commonly used linearlayout linear layouts



Android 0 Basics Section 26th: Two alignments, layout_gravity and gravity differ greatly



Android 0 Basics section 27th: Using padding and margin correctly



Android 0 Basics Section 28th: Easy to master relativelayout relative layout



Android 0 Basics 29th: Use tablelayout table layouts



Android 0 Basics 30th: Two minutes master Framelayout frame layout



Android 0 Basics Section 31st: absolutelayout absolute Layout with less



Android 0 Basics Section 32nd: New GridLayout Grid layout



Android 0 Basics section 33rd: Android Event Handling overview



Android 0 Basics Section 34th: Listening-based event handling in Android



Android 0 Basics Section 35th: Callback-based event handling in Android



Android 0 Basics Section 36th: Handling of Android system events



Android 0 Basics 37th: First Knowledge ListView



Android 0 Basics 38th: First Knowledge Adapter



Android 0 Basics section 39th: listactivity and custom list items



Android 0 Basics Section 40th: Customizing Arrayadapter



Android 0 Basics Section 41st: Using Simpleadapter



Android 0 Basics Section 42nd: Customizing Baseadapter



Android 0 Basics section 43rd: ListView Optimization and List End-to-end use



Android 0 Basics Section 44th: ListView Data Dynamic Update



Android 0 Basic Getting Started section 45th: Grid view GridView



Android 0 Basics section 46th: List Options Box spinner



Android 0 Basic Getting Started section 47th: AutoComplete text Box Autocompletetextview



Android 0 Basics Section 48th: Collapsible list Expandablelistview



Android 0 Basics section 49th: Adapterviewflipper picture Carousel



Android 0 Basics Section 50th: StackView card Stacking



Android 0 Basics Section 51st: progress bar ProgressBar



Android 0 Basics section 52nd: Customizing ProgressBar Cool progress bar



Android 0 Basics 53rd: Drag bar Seekbar and star rating bar Ratingbar



Android 0 Basics section 54th: View switch Components Viewswitcher



Android 0 Basics Section 55th: Imageswitcher and Textswitcher



Android 0 Basics Section 56th: Flip View Viewflipper



Android 0 Basics Section 57th: DatePicker and Timepicker selectors



Android 0 Basics Section 58th: Value selector numberpicker









Android 0 Basics section 59th: AnalogClock, DigitalClock, and textclock clock components


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.