In Android Studio choose New Project → Empty Views Activity, with Language Java and Minimum SDK API 24. To copy the code below unchanged, use the package name com.example.simplelogin.
2. Add the welcome screen
Right-click your package and choose New → Activity → Empty Views Activity. Name it NewActivity.
3. Build the form with Material text fields
In activity_main.xml, wrap each TextInputEditText in a TextInputLayout. You get a floating label, a place for error messages, and for the password, app:endIconMode="password_toggle" adds the eye icon that shows or hides it.
4. Hide the password
Give the password field android:inputType="textPassword", so it shows dots.
5. Check the details
When Log in is tapped, read both fields. If one is empty, call setError on its TextInputLayout so the message appears right under that box.
6. Compare with the right values
This first app compares with fixed values: username user, password 123456. If they match, open NewActivity with an Intent and pass the username along. If not, show Wrong username or password.
7. Welcome the user
NewActivity reads the username from the intent and shows "Welcome, user!". Log out calls finish(), which returns to the login screen.
8. Run it
Try wrong details first to see the error, then log in with user / 123456.
The welcome screen is included (the original post left it out), errors show under the right field, the password hides with a show/hide toggle, and the layout uses Material 3.
Files affected
Check what to add and what to replace before copying code.
Checks the username and password and opens the welcome screen.
MainActivity.java
packagecom.example.simplelogin;importandroid.content.Intent;importandroid.os.Bundle;importandroid.widget.Button;importandroidx.appcompat.app.AppCompatActivity;importcom.google.android.material.textfield.TextInputEditText;importcom.google.android.material.textfield.TextInputLayout;/**
* A first login screen: checks the username and password against fixed values.
* Real apps check against a database or a server; see the SQLite and Firebase login tutorials.
*/publicclassMainActivityextendsAppCompatActivity{privatestaticfinalStringUSERNAME="user";privatestaticfinalStringPASSWORD="123456";TextInputLayout loginLayout, passwordLayout;TextInputEditText loginText, passwordText;Button btnLogin;@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);Screens.setUp(this,R.layout.activity_main);
loginLayout =findViewById(R.id.loginLayout);
passwordLayout =findViewById(R.id.passwordLayout);
loginText =findViewById(R.id.login);
passwordText =findViewById(R.id.password);
btnLogin =findViewById(R.id.buttonLogin);
btnLogin.setOnClickListener(view ->{String username =String.valueOf(loginText.getText()).trim();String password =String.valueOf(passwordText.getText());// Show problems right under the box they belong to.
loginLayout.setError(username.isEmpty()?getString(R.string.error_username):null);
passwordLayout.setError(password.isEmpty()?getString(R.string.error_password):null);if(username.isEmpty()|| password.isEmpty())return;if(username.equals(USERNAME)&& password.equals(PASSWORD)){Intent intent =newIntent(this,NewActivity.class);
intent.putExtra("USERNAME", username);startActivity(intent);
passwordText.setText("");}else{
passwordLayout.setError(getString(R.string.error_invalid));}});}}