Digital Clock is a very useful widget in android to show time in your application.
Here is a simple demo on using digital Clock widget.

First In the layout file copy this file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center|center_vertical"
    android:background="@drawable/android_3"
    >

<DigitalClock
	android:text="Digital Clock"
	android:id="@+id/DigitalClock01"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="@drawable/header_bg"
	android:gravity="center|center_vertical"
	android:layout_gravity="center|center_vertical"

	android:layout_margin="10dp">
</DigitalClock>
</LinearLayout>

This creates a digital clock widget in the UI which will automatically update the time from the device.

Now in the java file you can reference it like this.
Since Digital Clock extends TextView you can apply every methods that you apply on a TextView.

        DigitalClock dg;
        dg = (DigitalClock)findViewById(R.id.DigitalClock01);
        dg.setTextColor(Color.RED);
        dg.setTextSize(25f);

Digital Clock Demo in Android

Please leave your comments on this post.

 

One Comment

  1. Paris Vy October 27, 2014 at 7:14 pm

    Many thanks for the great article, I was hunting for details such as this, going to check out the various other blog posts.

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.