<?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"
tools:context="semicolonprogramming.semicolonprogramming.blogspot.in.login.MainActivity">
<EditText
android:id="@+id/et_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="165dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Email"
android:textAlignment="center"/>
<EditText
android:id="@+id/et_pswd"
android:hint="Password"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/et_id"
android:layout_alignRight="@+id/et_id"
android:layout_below="@+id/et_id"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/et_pswd"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp"
android:text="Login" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:text="Simple Log In Screen"
android:textSize="25sp"
android:textColor="#000000"
android:textStyle="bold"/>
</RelativeLayout>
MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText et_id, et_pswd;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_id = (EditText)findViewById(R.id.et_id);
et_pswd = (EditText)findViewById(R.id.et_pswd);
btn=(Button)findViewById(R.id.btn_login);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(et_id.getText().toString().equals("")) {
et_id.setError("Please enter Email Id");
} else if(et_pswd.getText().toString().equals("")){
et_pswd.setError("Please enter password");
}
else{
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
}
});
}
}
Main2Activity.xml
<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"
tools:context="semicolonprogramming.semicolonprogramming.blogspot.in.login.Main2Activity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome"
android:textAlignment="center"
android:textSize="35sp"
android:textColor="#000000"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="222dp" />
</RelativeLayout>
Main2Activity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
Output:
No comments:
Post a Comment