Q10

Question 10

Create a Login application (check username and password). On successful login, pop up a message. ("Welcome username")

App Insights:

Hard coded username and password values, use EditText, TextView and Button. Added Toast widget for both successful and failed login attempt

Browse Source Code

Code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Login Application"
        android:layout_marginTop="25dp"
        android:textSize="25dp"
        android:textColor="@color/black"
        />

    <TextView
        android:id="@+id/t2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_marginTop="250dp"
        android:text="Username"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/t1"
        android:layout_marginLeft="50dp" />

    <TextView
        android:id="@+id/t3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="280dp"
        android:text="Password"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/t2" />

    <EditText
        android:id="@+id/e1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="120dp"
        android:layout_marginTop="230dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintStart_toEndOf="@id/t2"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="50dp" />

    <EditText
        android:id="@+id/e2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="120dp"
        android:layout_marginTop="260dp"
        android:ems="10"
        android:inputType="textPassword"
        app:layout_constraintLeft_toRightOf="@id/t3"
        app:layout_constraintTop_toBottomOf="@id/t2" />

    <Button
        android:id="@+id/b1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:onClick="check"
        android:text="Login"
        android:layout_marginTop="230dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</RelativeLayout>

Output

Studio Screenshot Main Activity (Login Page) (1/9)
App Screenshot Main Activity (Login Page) (2/9)
Studio Screenshot Taking User Credentials (3/9)
App Screenshot Taking User Credentials (4/9)
Studio Screenshot Taking User Credentials (5/9)
Studio Screenshot Validating User With Welcome Toast (6/9)
App Screenshot Validating User With Welcome Toast (7/9)
Studio Screenshot Validating User With Invalid Toast (8/9)
App Screenshot Validating User With Welcome Toast (9/9)

Last updated