
Estimated time: 30 minutes
Welcome to the lab on building a registration screen user interface in Android Studio. You will use the linear layout along with multiple widgets to build the view. The final result would look something like this:

After completing this lab, you will be able to:
This is an instructional lab that does not require a Skills Network lab environment. You will follow this lab on your local machine using Android Studio.
Creating a registration screen involves a careful balance of usability and data collection. Users should find the form easy to complete without feeling overwhelmed by too many fields. Registration forms should be straightforward and clear.
Key elements of a good UX include: - Logical grouping of fields - Clear labeling - Appropriate input types to enhance user experience and data integrity
The lab introduces a few new widgets:
You can skip this step if you already have the project from the previous lab open in Android Studio.
In the project tool window, navigate to
app > src > main > com > example > loginapplication
directory.
Right-click on the directory, select
New > Activity -> Empty Views Activity.

Name the activiy RegisterViewActivity and the
corresponding view register_view.

This should creatre a Java files named
RegisterViewActivity.java and a corresponding view named
register_view.xml

Open the register_view.xml file in
design view.
Right click the main layout in the component tree
and select Convert view

You want to convert to ScrollView. This option is
not available and you will have type it out.

You might notice a red flag and an issue "Speakable text not
present." This will do away once you add a LinearLayout to
the canvas. Drop a LinearLayout from the widget library to
the canvas.
Since you have already worked with the drag-and-drop interface in the design view, the lab does not provide any further screenshots. You will however be given all the properties that need to be set for each field.
Drag a LinearLayout (vertical) from the Palette to
the ScrollView.
Check the orientation is set to
vertical.
Drag a TextView from the Palette to the
LinearLayout.
In the Attributes panel, set the id to
app_title.
Set the text to Register.
Set the layout_margin to 24dp.
Set the textSize to 24sp.
Set the gravity to center.
Set padding to 16dp.
At the end of this step, you should have a TextView that
serves as the title text of your registration screen.
Drag an E-mail from the Palette to the
LinearLayout, below the TextView. If it is
hard to drop it in the linear layout, you can always add it to the
component tree.
In the Attributes panel, set the id to
email.
Set minHeight to 48dp.
Delete the text attribute if present and set the
hint to Email (Username).
Confirm that the inputType is
textEmailAddress.
Set layout_margin to 16dp.
Drag an Password item from the Palette to the
LinearLayout, below the Email EditText.
In the Attributes panel, set the id to
password.
Delete the text attribute and set the
hint to Password.
Confirm the inputType is set to
textPassword.
Set minHeight to 48dp.
Set layout_margin to 16dp.
Drag a PlainText from the Palette to the
LinearLayout, below the Password EditText.
In the Attributes panel, set the id to
full_name.
Delete the Name from the text attribute
and set the hint to Full Name.
Confirm that the inputType is
text.
Set minHeight to 48dp.
Set layout_margin to 16dp.
Drag a Phone text item from the Palette to the
LinearLayout, below the Full Name EditText.
In the Attributes panel, set the id to
phone_number.
Set the hint to Phone Number.
Confirm that the inputType is
phone.
Set minHeight to 48dp.
Set layout_margin to 16dp.
Drag a TextView from the Palette to the
LinearLayout, below the Phone Number EditText.
In the Attributes panel, set the text to
Gender.
Set the layout_margin to 16dp.
Drag a RadioGroup from the Palette to the
LinearLayout, below the Gender TextView.
In the Attributes panel, set the id to
gender_group.
Add three RadioButton widgets inside the RadioGroup with ids
male, female, and other.
Set the text for each RadioButton to Male,
Female, and Other, respectively.
Drag a CheckBox from the Palette to the
LinearLayout, below the RadioGroup.
In the Attributes panel, set the id to
agree_checkbox.
Set the text to Agree? Privacy Notice.
Set the layout_margin to 16dp.
Drag a Button from the Palette to the
LinearLayout, below the CheckBox.
In the Attributes panel, set the id to
register_button.
Set the text to Register.
Set layout_margin to 10dp.
Drag a TextView from the Palette to the
LinearLayout, below the Register Button.
In the Attributes panel, set the id to
login_link.
Set the text to
Already have an account?
Set the textColor to a color resource or a hex value
to make it look like a link (e.g., #0000FF for
blue).
Set the textSize to 16sp.
Set layout_marginTop to 8dp.
The app/src/main/AndroidManifest.xml file tells
Android Studio about what activity to run when the app starts. Open this
file and change the following text
<activity
android:name=".RegisterViewActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
to
<activity
android:name=".RegisterViewActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>Ensure your AVD is set up from the previous lab.
Select the Run button in Android Studio.
Select your AVD and wait for the application to launch.
Verify that the registration screen appears as designed.
Once you have tested your application, change back the code to the
previous version in app/src/main/AndroidManifest.xml file.
This ensures the login screen is first shown when the user launches the
application on the phone. This is important for future labs.
You have now successfully created the UI for a registration screen
using LinearLayout. This foundational skill will be crucial
as you continue to develop more complex UIs in your Android
applications.
If you are really stuck, you can copy the file before into
register_view.xml file to get the same screen as the
lab.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/app_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:gravity="center"
android:text="Register"
android:textSize="24sp" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:minHeight="48dp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:ems="10"
android:hint="password"
android:inputType="textPassword"
android:minHeight="48dp" />
<EditText
android:id="@+id/full_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:ems="10"
android:hint="Full Name"
android:inputType="text"
android:minHeight="48dp" />
<EditText
android:id="@+id/phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
android:minHeight="48dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Gender" />
<RadioGroup
android:id="@+id/gender_group"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
<RadioButton
android:id="@+id/male"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female" />
<RadioButton
android:id="@+id/other"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Other" />
</RadioGroup>
<CheckBox
android:id="@+id/agree_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Agree? Privacy Notice" />
<Button
android:id="@+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Register" />
<TextView
android:id="@+id/login_link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Already have an account?"
android:textColor="#0000FF"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
Author
UL