Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement app login interface with Android studio

Shulou Source: shulou.com Published: 2022-05-31 20:05:52 10月04日 Update

This article mainly introduces Android studio how to achieve app login interface related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Android studio how to achieve app login interface article will have a harvest, let's take a look.

Android studio designs app login interface

UI interface design

When designing the login interface, you can use different layouts to achieve this function, usually using LinearLayout (linear layout) and TableLayout (table layout), and linear layout is used in this article. The login interface requires several essential controls, as follows:

TextView: tips for displaying title and "user name" and "password"

Title Settin

User name prompt

Password prompt:

EditView: used to enter user name and password

User name input box:

Password input box:

Button: used to control login.

Button login button:

/ >

This article uses three layers of LinearLayout to nest each other, and the first layer of LinearLayout includes the title (TextView), the second layer LinearLayout and the login button (Button). The first layer of LinearLayout uses vertical distribution, that is, android:orientation= "vertical".

Two layer 3 LinearLayout are nested in the second layer LinearLayout, and the second layer LinearLayout is vertically distributed, that is, android:orientation= "vertical".

The two LinearLayout in the third layer each contain a TextView and an EditView, and the third layer LinearLayout is a horizontal distribution, that is, android:orientation= "horizontal".

The overall UI design is shown below.

/ >

The effect is shown in the figure.

Java code writing

If the user enters the user name or password incorrectly, the pop-up window prompts "the user name or password is entered incorrectly, please correct it and re-enter it!" .

If the user does not enter a user name or password, the pop-up window prompts "the user name and password cannot be empty!" .

Only when the user name and password are entered correctly at the same time can you enter the system.

Package com.example.activities

Import android.content.Intent

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 MainActivity extends AppCompatActivity {

Private EditText usertext

Private EditText passtext

Private Button loginbutton

@ Override

Protected void onCreate (Bundle savedInstanceState) {

Super.onCreate (savedInstanceState)

SetContentView (R.layout.activity_main)

Usertext= (EditText) this.findViewById (R.id.ed1)

Passtext= (EditText) this.findViewById (R.id.ed2)

Loginbutton= (Button) this.findViewById (R.id.bt)

Loginbutton.setOnClickListener (new ButtonListener ())

}

Private class ButtonListener implements View.OnClickListener {

@ Override

Public void onClick (View v) {

String user=usertext.getText () .toString ()

String pass=passtext.getText () .toString ()

If (user.equals (") | | pass.equals (")) {

Toast.makeText (MainActivity.this, "username and password cannot be empty!" , Toast.LENGTH_SHORT) .show ()

}

Else if (user.equals ("denglu") & & pass.equals ("0000")) {

Toast.makeText (MainActivity.this, "login succeeded", Toast.LENGTH_SHORT) .show ()

Intent intent=new Intent (MainActivity.this,TwoActivity.class)

StartActivity (intent)

}

Else {

Toast.makeText (MainActivity.this, "user name or password was entered incorrectly, please correct it and re-enter it!" , Toast.LENGTH_SHORT) .show ()

}

}

}

}

After clicking the login button, go to the next interface. Add the name of the second Activity to the Manifest.

Tags: User password user name login input interface prompt layout design second layer button title knowledge two content article linear page login different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft MariaDB Docker Apple