Como hacer un login en android studio

A login applications is the screen asking her credentials come login to some particular application. You might have seen it once logging into facebook,twitter e.t.c

This chapter explains, just how to create un login screen y how to manage security once false attempts space made.

Estás mirando: Como hacer un login en android studio

First you have actually to definir two TextView questioning username y password of ns user. Ns password TextView must have actually inputType set to password. That is syntax is given listed below −

Define ns button con login text and set its onClick Property. Delaware that definir the duty mentioned in los onClick residential property in the java file.

In the java file, inside los method of onClick get ns username and passwords message using getText() and toString() method and match the with the text making use of equals() function.

EditText username = (EditText)findViewById(R.id.editText1);EditText password = (EditText)findViewById(R.id.editText2);public void login(View view){ if(username.getText().toString().equals("admin") && password.getText().toString().equals("admin")) //correcct password else //wrong passwordThe último thing you must do is to provide un security mechanism, for this reason that undesirable attempts must be avoided. Because that this initialize a variable y on each false attempt, decrement it. And when it reaches to 0, disable ns login button.

int counter = 3;counter--;if(counter==0) //disble the button, close los application e.t.c

Example

Here is an instance demonstrating ns login application. The creates uno basic application that offers you only numero 3 attempts come login to an application.

To experiment with this example, girlfriend can operación this top top an en la actualidad device or in one emulator.

StepsDescription
1You will use Android studio to develop an Android application under un package com.example.sairamkrishna.myapplication.

Ver más: Como Pasar Megas De Un Celular A Otro Usuario, ▷ Cómo Pasar Megas De Un Celular Movistar A Otro

3Modify src/MainActivity.java file to add necessary code.
4Modify los res/layout/activity_main to include respective XML components
5Run the application and choose a corriendo android device and install the application top top it y verify los results

Following is los content of the modified key activity archivo src/MainActivity.java.

package com.example.sairamkrishna.myapplication;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends task button b1,b2; EditText ed1,ed2; TextView tx1; int counter = 3;
Override defended void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button)findViewById(R.id.button); ed1 = (EditText)findViewById(R.id.editText); ed2 = (EditText)findViewById(R.id.editText2); b2 = (Button)findViewById(R.id.button2); tx1 = (TextView)findViewById(R.id.textView3); tx1.setVisibility(View.GONE); b1.setOnClickListener(new View.OnClickListener()
Override windy void onClick(View v) if(ed1.getText().toString().equals("admin") && ed2.getText().toString().equals("admin")) Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show(); else Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show(); tx1.setVisibility(View.VISIBLE); tx1.setBackgroundColor(Color.RED); counter--; tx1.setText(Integer.toString(counter)); if (counter == 0) b1.setEnabled(false); ); b2.setOnClickListener(new View.OnClickListener()
Override public void onClick(View v) finish(); ); Following is los modified contents of los xml res/layout/activity_main.xml.

In los following password abc shows about logotipo of circulocreativolondon.com

no no no complying with is los content of ns res/values/string.xml.

my ApplicationFollowing is los content that AndroidManifest.xml file.

no Let"s shot to correr our applications we just modified. Me gustaría assume you had developed your AVD when doing atmosphere setup. To operación the app from Android studio, open one of your project"s activity files y click correr

*
icon from the toolbar. Android studio installs ns app on her AVD and starts it y if every little thing is fine with your setup and application, the will screen following Emulator home window −

*

Type anything in ns username and password field, and then press the login button. Me gustaría put alphabet in the username field and abc in ns password field. Identificación got failure attempt. This is shown below −

*

Do this dos more time, and you will watch that you have 0 login attempts left y your login switch is disabled.

Ver más: Como Subir Fotos A Google Drive Desde Mi Celular Subiendo Fotos A La Nube

Now open los application again, y this tiempo enter correct username as admin y password together admin y click on login. You will be efficiently login.