How to make digital clock inside android application to show current device time with AM-PM formats.
Digital clock is a simple clock with digital format like we have already seen on android phone title bar. Digital clock is used to show current device time with AM-PM formats in 12-hours format. So here is the complete step by tutorial for Android Create/Show Digital Clock Widget Example with AM/PM.
Android Create/Show Digital Clock Widget Example with AM/PM.
Code for MainActivity.java file.
package com.digitalclock_android_examples.com; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Code for activity_main.xml layout file.
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.digitalclock_android_examples.com.MainActivity" > <DigitalClock android:id="@+id/digitalclock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textSize="25dp" /> </RelativeLayout>
Screenshot: