Advertisement
Guest User

login

a guest
Mar 1st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.61 KB | None | 0 0
  1. package com.example.com.mylogin;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.Toast;
  8.  
  9. public class MainActivity extends Activity
  10. {
  11.     EditText txtUser;
  12.     EditText txtPass;
  13.  
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.activity_main);
  18.         setPointer();
  19.     }
  20.  
  21.     public void setPointer()
  22.     {
  23.         txtUser=(EditText)findViewById(R.id.user);
  24.         txtPass=(EditText)findViewById(R.id.pass);
  25.     }
  26.  
  27.     public void btnLogin(View v)
  28.     {
  29.         String chkUser = txtUser.getText().toString();
  30.         String chkPass = txtPass.getText().toString();
  31.  
  32.         if(chkUser.toLowerCase().equals("oorya") && chkPass.toLowerCase().equals("12345"))
  33.             Toast.makeText(this, "Hello "+chkUser, Toast.LENGTH_LONG).show();
  34.         else
  35.             Toast.makeText(this, "Wrong User", Toast.LENGTH_LONG).show();
  36.     }
  37.  
  38. }
  39. ================================================xml
  40.  
  41. <LinearLayout
  42.     android:layout_width="match_parent"
  43.     android:layout_height="match_parent"
  44.     android:orientation="vertical"
  45.     xmlns:android="http://schemas.android.com/apk/res/android"
  46.     android:gravity="center">
  47.  
  48.     <LinearLayout
  49.         android:layout_width="match_parent"
  50.         android:layout_height="match_parent"
  51.         android:layout_weight="1"
  52.         android:orientation="vertical"
  53.         android:id="@+id/top"
  54.         android:weightSum="1">
  55.  
  56.         <ImageView
  57.             android:layout_width="wrap_content"
  58.             android:layout_height="match_parent"
  59.             android:id="@+id/imageView"
  60.             android:src="@drawable/hackeru"/>
  61.     </LinearLayout>
  62.  
  63.     <RelativeLayout
  64.         android:layout_width="match_parent"
  65.         android:layout_height="match_parent"
  66.         android:layout_weight="1"
  67.         android:orientation="vertical"
  68.         android:id="@+id/mid"
  69.         android:gravity="center"
  70.         android:weightSum="1">
  71.  
  72.         <EditText
  73.             android:layout_width="match_parent"
  74.             android:layout_height="wrap_content"
  75.             android:hint="@string/enter_user"
  76.             android:textSize="24sp"
  77.             android:inputType="text"
  78.             android:id="@+id/user"/>
  79.  
  80.         <EditText
  81.             android:layout_width="match_parent"
  82.             android:layout_height="wrap_content"
  83.             android:hint="@string/enter_pass"
  84.             android:textSize="24sp"
  85.             android:inputType="textPassword"
  86.             android:id="@+id/pass"
  87.             android:layout_below="@+id/user"/>
  88.     </RelativeLayout>
  89.  
  90.     <LinearLayout
  91.         android:layout_width="match_parent"
  92.         android:layout_height="match_parent"
  93.         android:layout_weight="1"
  94.         android:orientation="vertical"
  95.         android:id="@+id/bot"
  96.         android:gravity="center">
  97.  
  98.         <Button
  99.             android:layout_width="wrap_content"
  100.             android:layout_height="wrap_content"
  101.             android:text="Login"
  102.             android:textSize="30dp"
  103.             android:id="@+id/button"
  104.             android:background="#8aa2bfdf"
  105.             android:layout_gravity="center_horizontal"
  106.             android:onClick="btnLogin"/>
  107.     </LinearLayout>
  108. </LinearLayout>
  109. =============================================values
  110. <resources>
  111.     <string name="app_name">My Login</string>
  112.     <string name="action_settings">Settings</string>
  113.     <string name="enter_user">Enter user name</string>
  114.     <string name="enter_pass">Enter password</string>
  115. </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement