Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
120 views3 pages

XML File Coding: Relativelayout

This document contains code for an XML file and Java file to create a login screen application in Android. The XML file defines the layout of the login screen with textviews and edittext for email and password, and buttons for login and signup. The Java file imports necessary libraries, gets references to the email, password, and login button from the XML layout, adds an onclick listener to the login button to check credentials and display a toast message.

Uploaded by

Muhammad Ayaan
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)
120 views3 pages

XML File Coding: Relativelayout

This document contains code for an XML file and Java file to create a login screen application in Android. The XML file defines the layout of the login screen with textviews and edittext for email and password, and buttons for login and signup. The Java file imports necessary libraries, gets references to the email, password, and login button from the XML layout, adds an onclick listener to the login button to check credentials and display a toast message.

Uploaded by

Muhammad Ayaan
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/ 3

XML File Coding

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout 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="#762324">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="30px"
android:layout_marginLeft="55dp"
android:layout_marginTop="100dp"
android:width="100dp"
android:height="20dp"
/>

<EditText
android:layout_width="180dp"
android:layout_height="30dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="140dp"
android:id="@+id/email"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_marginLeft="55dp"
android:layout_marginTop="150dp"
android:width="70dp"
android:textSize="30px"/>

<EditText
android:layout_width="180dp"
android:layout_height="30dp"
android:layout_marginLeft="140dp"
android:layout_marginTop="150dp"
android:inputType="textPassword"
android:id="@+id/password"/>

<Button
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="220dp"
android:text="login"
android:id="@+id/login"
android:background="#ffff"
android:textColor="#762324" />
<Button
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_marginTop="260dp"
android:layout_marginLeft="90dp"
android:text="SignUp"
android:background="#ffff"
android:textColor="#762324"
/>

</RelativeLayout>

Java File Coding

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 Final extends AppCompatActivity {

EditText email,password;
Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
email=(EditText) findViewById(R.id.email);
password=(EditText)findViewById(R.id.password);
login=(Button) findViewById(R.id.login);

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String mail=email.getText().toString();
String pass=password.getText().toString();
if(mail.equals("ABC") && pass.equals("123")){
Toast.makeText(Final.this,mail+" "+pass,Toast.LENGTH_LONG).show();

}
else {

Toast.makeText(Final.this, "Error",Toast.LENGTH_SHORT).show();
}
}
});
}
}

You might also like