How to create responsive android login screen from scratch

In this tutorial we are creating a responsive android login screen from scratch

To begin create  android project file > new >new project>start with empty activity

Now you can use content _main.xml or you can create xml file by right click on layout folder>new>XML>layout xml named it as content.xml. and type the following code , in this we are creating the UI login screen.

To make your login screen more responsive here i will use google card view.

Go to your build.gradle (module:app)>add following code 
dependencies {
    implementation 'com.android.support:cardview-v7:28.0.0'
    
}
Now open your content_main.xml and start codding.............
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    android:background="@drawable/wal"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main">


    <androidx.cardview.widget.CardView


        android:layout_width="350dp"
        android:layout_height="70dp"
        android:background="#fff"
        android:elevation="@dimen/fab_margin"
        app:cardBackgroundColor="#fff"
        app:cardCornerRadius="10dp"
        app:cardElevation="15dp"
        app:cardMaxElevation="3dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.353">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="49dp"
            android:background="@drawable/a"
            android:contentDescription="TODO" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="85dp"
            android:text="@string/username"
            android:textAlignment="center"
            android:textColorHint="#000">

        </EditText>

    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView


        android:layout_width="350dp"
        android:layout_height="70dp"
        android:background="#fff"
        android:elevation="@dimen/fab_margin"
        app:cardBackgroundColor="#fff"
        app:cardCornerRadius="10dp"
        app:cardElevation="15dp"
        app:cardMaxElevation="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:layout_width="44dp"
            android:layout_height="47dp"
            android:background="@drawable/key"
            android:contentDescription="TODO" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="82dp"
            android:text="password"
            android:textAlignment="center"
            android:textColorHint="#000">

        </EditText>
    </androidx.cardview.widget.CardView>

    <Button

        android:id="@+id/button"
        android:layout_width="309dp"
        android:layout_height="59dp"
        android:background="#31b7ff"
        android:text="Sign In"
        android:textColor="#fff"
        android:textSize="38dp"
        android:textStyle="italic"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.588"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.913" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:layout_marginEnd="141dp"
        android:layout_marginRight="141dp"
        android:layout_marginBottom="522dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.992"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        app:srcCompat="@drawable/ai" />


</androidx.constraintlayout.widget.ConstraintLayout>

You can choose drawable’s of your choice >Add drawable’s in res>drawable

Now finally run your project(shift+f10) or from menu bar select run , you can use android emulator or you can use your device as emulator.

Output

 

Hits: 157

Tags: No tags

Share your thoughts