Advertisement
Guest User

my login - 1

a guest
Apr 25th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.81 KB | None | 0 0
  1. LoginActivity.java
  2. --------------------------------
  3.  
  4.  
  5. package com.example.teacher.mylogin;
  6.  
  7. import android.content.Context;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.Toast;
  14.  
  15. public class LoginActivity extends AppCompatActivity {
  16.  
  17.     Context context;
  18.  
  19.     Button btnLog, btnReg;
  20.     EditText txtUser, txtPass;
  21.    
  22.     @Override
  23.     protected void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.activity_login);
  26.        
  27.         setPointer();
  28.     }
  29.  
  30.     private void setPointer() {
  31.         context = this;
  32.  
  33.         btnLog = findViewById(R.id.logBtnLogin);
  34.         btnReg = findViewById(R.id.logBtnReg);
  35.  
  36.         txtUser = findViewById(R.id.logTxtUser);
  37.         txtPass = findViewById(R.id.logTxtPass);
  38.  
  39.         btnLog.setOnClickListener(new View.OnClickListener() {
  40.             @Override
  41.             public void onClick(View view) {
  42.  
  43.                 final String USER = "admin";
  44.                 final String PASS = "123456";
  45.  
  46.                 String enteredUser = txtUser.getText().toString();
  47.                 String enteredPass = txtPass.getText().toString();
  48.  
  49.                 if(enteredUser.equals(USER)&&enteredPass.equals(PASS)){
  50.                     Toast.makeText(context, getResources().getString(R.string.logMsgLogSuccess), Toast.LENGTH_SHORT).show();
  51.                 }
  52.                 else{
  53.                     Toast.makeText(context, getResources().getString(R.string.logMsgLogFail), Toast.LENGTH_SHORT).show();
  54.  
  55.                 }
  56.  
  57.             }
  58.         });
  59.  
  60.  
  61.     }
  62. }
  63.  
  64. -------------------------------------------
  65.  
  66. activity_login.xml
  67. -------------------------------------------
  68.  
  69. <?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  71.     android:layout_width="match_parent"
  72.     android:layout_height="match_parent"
  73.     android:orientation="vertical">
  74.  
  75.     <LinearLayout
  76.         android:layout_width="match_parent"
  77.         android:layout_height="match_parent"
  78.         android:layout_weight="1"
  79.         android:orientation="horizontal">
  80.  
  81.         <TextView
  82.             android:layout_width="match_parent"
  83.             android:layout_height="match_parent"
  84.             android:text="@string/logTxtLogo"
  85.             android:textSize="@dimen/logoText"
  86.             android:gravity="center"/>
  87.  
  88.     </LinearLayout>
  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.  
  96.         <EditText
  97.             android:id="@+id/logTxtUser"
  98.             android:layout_width="match_parent"
  99.             android:layout_height="match_parent"
  100.             android:layout_weight="1"
  101.             android:hint="@string/logUserHint"
  102.             android:textSize="@dimen/txtText"
  103.             android:layout_margin="@dimen/txtMargin"/>
  104.  
  105.         <EditText
  106.             android:id="@+id/logTxtPass"
  107.             android:layout_width="match_parent"
  108.             android:layout_height="match_parent"
  109.             android:layout_weight="1"
  110.             android:hint="@string/logPassHint"
  111.             android:textSize="@dimen/txtText"
  112.             android:layout_margin="@dimen/txtMargin"
  113.             android:inputType="numberPassword"/>
  114.     </LinearLayout>
  115.  
  116.     <LinearLayout
  117.         android:layout_width="match_parent"
  118.         android:layout_height="match_parent"
  119.         android:layout_weight="1"
  120.         android:orientation="horizontal"
  121.         android:gravity="center">
  122.  
  123.         <Button
  124.             android:id="@+id/logBtnLogin"
  125.             android:layout_width="match_parent"
  126.             android:layout_height="wrap_content"
  127.             android:layout_weight="1"
  128.             android:background="@color/btnBackground"
  129.             android:textColor="@color/btnText"
  130.             android:text="@string/logBtnLogin"
  131.             android:layout_margin="@dimen/btnMargin"/>
  132.  
  133.         <Button
  134.             android:id="@+id/logBtnReg"
  135.             android:layout_width="match_parent"
  136.             android:layout_height="wrap_content"
  137.             android:layout_weight="1"
  138.             android:background="@color/btnBackground"
  139.             android:textColor="@color/btnText"
  140.             android:text="@string/logBtnReg"
  141.             android:layout_margin="@dimen/btnMargin"/>
  142.     </LinearLayout>
  143.  
  144. </LinearLayout>
  145.  
  146.  
  147.  
  148. -------------------------------------------------------------------------
  149.  
  150. strings.xml
  151. ------------------------------------------------
  152. <resources>
  153.     <string name="app_name">MyLogin</string>
  154.     <string name="logTxtLogo">My Logo</string>
  155.     <string name="logUserHint">username</string>
  156.     <string name="logPassHint">password</string>
  157.     <string name="logBtnLogin">Login</string>
  158.     <string name="logBtnReg">Register</string>
  159.     <string name="logMsgLogSuccess">Login was successful</string>
  160.     <string name="logMsgLogFail">Failure to login</string>
  161. </resources>
  162.  
  163.  
  164. -----------------------------------------------
  165.  
  166. dimens.xml
  167. -----------------------------------------------
  168. <?xml version="1.0" encoding="utf-8"?>
  169. <resources>
  170.     <dimen name="txtText">24sp</dimen>
  171.     <dimen name="logoText">35sp</dimen>
  172.     <dimen name="txtMargin">10dp</dimen>
  173.     <dimen name="btnMargin">5dp</dimen>
  174. </resources>
  175.  
  176. ---------------------------------------------
  177.  
  178. color.xml
  179. --------------------------------------------
  180. <?xml version="1.0" encoding="utf-8"?>
  181. <resources>
  182.     <color name="colorPrimary">#3F51B5</color>
  183.     <color name="colorPrimaryDark">#303F9F</color>
  184.     <color name="colorAccent">#FF4081</color>
  185.     <color name="btnBackground">#009fff</color>
  186.     <color name="btnText">#fff</color>
  187. </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement