Chronometer
Chronometer:
Chronometer is an element in the interface that relates to theTIME element and serves as a clock/timer tool.
It also shows the elapsed time in hours, minutes seconds and in one hundredth of a second. The Chronometer class comes under Android framework and the full package name is android. widget package.
Example:
<LinearLayout 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"
tools:context=".ChronometerExample"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="CHRONOMETER"
android:textColor="@color/colorOrange"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/startButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Start"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent" />
<Button
android:id="@+id/stopButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/startButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Stop"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent" />
<Button
android:id="@+id/restartButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/stopButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Restart"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent" />
<Button
android:id="@+id/setFormat"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/restartButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Set Format"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent" />
<Button
android:id="@+id/clearFormat"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/setFormat"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Clear Format"
android:textColor="@color/colorWhite"
android:background="@color/colorAccent" />
<!-- chronometer with black background and red text color -->
<Chronometer
android:id="@+id/simpleChronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/clearFormat"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:padding="10dp"
android:textColor="@color/colorWhite"
android:textStyle="bold" />
</LinearLayout>
Output