Introduction
This blog explains to how to set the time in an Android app, using TimePicker in Android Studio.
Requirements
- Android Studio 2.1.3
If you want to set the time in an Android app, you should follow the steps given below.
Step 1
Now, open Android Studio and you can choose the file, followed by New. Afterwards, choose New Project.

Step 2
Here, you can create your application's name and choose where your project is stored on the location, and click Next button.

Now, we can select the version of Android -- Target Android Devices.

Step 3
Here, we can add the activity and click Next button.

Now, we can write the activity name and click Finish button.

Step 4
Now, open your project and you will go to activity_main.xml and afterwards, you will build the design. You should choose toolbox and if you want some options (TimePicker,TextView), use the drag and drop method.

Now, we can see the Graphical User Interface design.

Step 5
Here, you need to build on the design and write .XML code.
activity_mai.xml code.
- <?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" 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="xyz.rvconstructions.www.timepickerapp.MainActivity">
- <TimePicker android:id="@+id/simpleTimePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:background="#998f00" android:padding="20dp" android:timePickerMode="spinner" />
- <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="Time Is ::" android:textColor="#8c0099" android:textSize="20sp" android:textStyle="bold" />
- </RelativeLayout>






Join the conversation! Your thoughts help the community grow.