/*Create a login application (check username and password). On successful login, pop up the message(“Welcome username”).*/
FileName: activity_main.xml
<?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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="15"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="190dp"
android:id="@+id/editTextPass1"
android:hint="password" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="15"
android:layout_alignBottom="@+id/editTextPass"
android:layout_alignEnd="@+id/editTextPass"
android:layout_marginBottom="90dp"
android:id="@+id/editTextUser1"
android:hint="username" />
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextPass1"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:id="@+id/button1" />
</RelativeLayout>
FileName: MainActivity.java
/**
* Created by Parikshit on 01-01-2019.
*/
package com.ducskecode.login_page;
import android.content.Intent;
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 login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.editTextUser1);
password = (EditText) findViewById(R.id.editTextPass1);
login = (Button) findViewById(R.id.button1);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(username.getText().toString().equals("admin") &&
password.getText().toString().equals("admin")){
Toast.makeText(MainActivity.this, "Welcome to the login App " +
username.getText().toString(),
Toast.LENGTH_SHORT().show();
}
else{
Toast.makeText(MainActivity.this, "Invalid Details,sorry!!",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
No comments:
Post a Comment