package com.example.loginform;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
Button btn;
EditText ed1, ed2;
btn = findViewById(R.id.btnid);
ed1 = findViewById(R.id.ed1id);
ed2 = findViewById(R.id.ed2id);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = ed1.getText().toString().trim();
String password = ed2.getText().toString().trim();
if (validateInputs(username, password)) {
Toast.makeText(MainActivity.this, "Login Successful!!!", Toast.LENGTH_SHORT).show();
}
}
});
return insets;
});
}
private Boolean validateInputs(String username, String password) {
if (username.isEmpty() || password.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter a username and password!", Toast.LENGTH_SHORT).show();
return false;
}
if (username.equals("admin") && password.equals("1234")) {
return true;
} else {
Toast.makeText(MainActivity.this, "Invalid username or password!", Toast.LENGTH_SHORT).show();
return false;
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter