To display an analog clock, Android provides the android.widget.AnalogClock class and to display a digital clock Android provides the android.widget.DigitalClock class. Any of these clocks can be used to show time in an Android application. The View class in Android has a subclass named Android AnalogClock, while the TextView class has a subclass named Android DigitalClock. It is, however, deprecated, since Android API level 17. After this, the TextClock is recommended to be used. In API level 23, the AnalogClock widget was deprecated and is no longer supported. Thus, now a hard code will be required to use AnalogClock in an application. In API level 27, it is not available to be dragged from the palette. The DatePicker and TimePicker can be used to change the time of the device. To display analog and digital clocks in android, the analog and digital clocks need to be dragged from the pallet.
activity_main.xml:
In the activity_main.xml file, we will drag the analog and digital clocks.
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="MainActivity"> <AnalogClock android:id="@+id/analogClock1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginLeft="136dp" android:layout_marginTop="296dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <DigitalClock android:id="@+id/digitalClock1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/analogClock1" android:layout_centerHorizontal="true" android:layout_marginLeft="176dp" android:layout_marginTop="84dp" android:text="DigitalClock" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
Activity class:(File: MainActivity.java)
In the MainActivity.java file, we are not adding any code.
package com.example.radioapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } |