Make a Login Activity in Android Studio

 Make a Login Activity in Android Studio 


In this tutorial, we will show you how to design the user interface of a beautiful login activity using android studio, in the second part of this tutorial we will show you how can we activate our login form by adding some java code.

Create a new Project

Let's start by opening Android Studio and create a new project

Then choose empty activity and click on next

- Type the project name and choose the minimum API level and click on finishand now let's start to code our user interface for that select the "activity_main.xml" and place the code bellow
N.B: for this tutorial, we will use an image as a background for our first TextView so you can choose any image that you want and place it inside the folder Drawable, also we will create a custom shape for the background of the button.


Activity_main.xml


Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="MainActivity"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:text="Login"
        android:paddingVertical="35dp"
        android:textAlignment="center"
        android:textSize="60sp"
        android:fontFamily="cursive"
        android:textColor="#000000"
        android:background="@drawable/bgtext"
        android:layout_marginBottom="25dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_marginHorizontal="30dp"
        android:layout_height="wrap_content"
        android:text="User name"
        android:textColor="#FF1493"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_marginHorizontal="30dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_marginHorizontal="30dp"
        android:layout_height="wrap_content"
        android:text="Password"
        android:textColor="#FF1493"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword"
        android:paddingHorizontal="12dp"
        android:paddingVertical="20dp"
        android:layout_marginHorizontal="30dp"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"
        android:layout_marginHorizontal="30dp"
        android:layout_marginVertical="20dp"
        android:background="@drawable/button_bg"
        android:textColor="#FFFFFF"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="No Account yet? Create One"
        android:layout_marginHorizontal="30dp"
        android:textAlignment="center"
        />
</LinearLayout>

Before you run the code let's create a custom a new file called "button_btn.xml" inside the drawable folder


And copy this code inside that file:

Code:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#7613ff"
        android:endColor="#f91cff"
        >

    </gradient>
    <corners android:radius="50dp">
    </corners>
</shape>

Finally, Now you can run you project and see the result.

Comments