0% found this document useful (0 votes)
106 views

Log in App For Android

This Android application code defines a login screen with username and password fields and a login button. When the button is clicked, it gets the text from the fields and calls a login method. The login method checks if the username and password match expected values, and displays a toast message indicating a successful or failed login attempt. The layout code defines the visual structure of the login screen with the two text fields above a button.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Log in App For Android

This Android application code defines a login screen with username and password fields and a login button. When the button is clicked, it gets the text from the fields and calls a login method. The login method checks if the username and password match expected values, and displays a toast message indicating a successful or failed login attempt. The layout code defines the visual structure of the login screen with the two text fields above a button.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.example.androidapps.

loginapps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText username,password;
Button btnlogin;
String user,pass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

username=findViewById(R.id.txtuser);
password=findViewById(R.id.txtuser);
btnlogin=findViewById(R.id.btnlogin);

btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
user=username.getText().toString().trim();
pass=password.getText().toString().trim();
login();
}
});
}

public void login() {

if(user.equals("ilias")&& pass.equals("ilias"))
{
Toast.makeText(this,"username and password
matched!",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(this,"username and password do not
matched!",Toast.LENGTH_LONG).show();
}
}
}

<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity">
<EditText

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="23dp"
android:id="@+id/txtuser"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="Username"
android:textSize="20sp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_marginTop="22dp"
android:id="@+id/txtpass"
android:hint="Password"
android:textSize="20sp"
android:layout_below="@+id/txtuser"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="@+id/btnlogin"
android:textSize="20sp"
android:layout_below="@+id/txtpass"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

</RelativeLayout>

You might also like