Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LoginActivity.java
- --------------------------------
- package com.example.teacher.mylogin;
- import android.content.Context;
- 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 LoginActivity extends AppCompatActivity {
- Context context;
- Button btnLog, btnReg;
- EditText txtUser, txtPass;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- setPointer();
- }
- private void setPointer() {
- context = this;
- btnLog = findViewById(R.id.logBtnLogin);
- btnReg = findViewById(R.id.logBtnReg);
- txtUser = findViewById(R.id.logTxtUser);
- txtPass = findViewById(R.id.logTxtPass);
- btnLog.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final String USER = "admin";
- final String PASS = "123456";
- String enteredUser = txtUser.getText().toString();
- String enteredPass = txtPass.getText().toString();
- if(enteredUser.equals(USER)&&enteredPass.equals(PASS)){
- Toast.makeText(context, getResources().getString(R.string.logMsgLogSuccess), Toast.LENGTH_SHORT).show();
- }
- else{
- Toast.makeText(context, getResources().getString(R.string.logMsgLogFail), Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
- -------------------------------------------
- activity_login.xml
- -------------------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="horizontal">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/logTxtLogo"
- android:textSize="@dimen/logoText"
- android:gravity="center"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <EditText
- android:id="@+id/logTxtUser"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:hint="@string/logUserHint"
- android:textSize="@dimen/txtText"
- android:layout_margin="@dimen/txtMargin"/>
- <EditText
- android:id="@+id/logTxtPass"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:hint="@string/logPassHint"
- android:textSize="@dimen/txtText"
- android:layout_margin="@dimen/txtMargin"
- android:inputType="numberPassword"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="horizontal"
- android:gravity="center">
- <Button
- android:id="@+id/logBtnLogin"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@color/btnBackground"
- android:textColor="@color/btnText"
- android:text="@string/logBtnLogin"
- android:layout_margin="@dimen/btnMargin"/>
- <Button
- android:id="@+id/logBtnReg"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@color/btnBackground"
- android:textColor="@color/btnText"
- android:text="@string/logBtnReg"
- android:layout_margin="@dimen/btnMargin"/>
- </LinearLayout>
- </LinearLayout>
- -------------------------------------------------------------------------
- strings.xml
- ------------------------------------------------
- <resources>
- <string name="app_name">MyLogin</string>
- <string name="logTxtLogo">My Logo</string>
- <string name="logUserHint">username</string>
- <string name="logPassHint">password</string>
- <string name="logBtnLogin">Login</string>
- <string name="logBtnReg">Register</string>
- <string name="logMsgLogSuccess">Login was successful</string>
- <string name="logMsgLogFail">Failure to login</string>
- </resources>
- -----------------------------------------------
- dimens.xml
- -----------------------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <dimen name="txtText">24sp</dimen>
- <dimen name="logoText">35sp</dimen>
- <dimen name="txtMargin">10dp</dimen>
- <dimen name="btnMargin">5dp</dimen>
- </resources>
- ---------------------------------------------
- color.xml
- --------------------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <color name="colorPrimary">#3F51B5</color>
- <color name="colorPrimaryDark">#303F9F</color>
- <color name="colorAccent">#FF4081</color>
- <color name="btnBackground">#009fff</color>
- <color name="btnText">#fff</color>
- </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement