Below is a complete Android Sign‑Up form with Social Login (Google / Facebook) built using Java and XML.
The layout uses Material Design components (TextInputLayout), includes email, password, name fields, a sign‑up button, and two social login buttons with icons.
The Java activity handles input validation, a dummy registration method, and click listeners for social login (with Firebase Auth stubs for easy integration).
1. XML Layout – activity_signup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:gravity="center_horizontal"
android:background="@color/white">
<!-- App Logo / Heading -->
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_app_logo"
android:layout_marginTop="32dp"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Account"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/primary_text"
android:layout_marginBottom="24dp"/>
<!-- Name -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:inputType="textPersonName"
android:maxLines="1"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Email -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"
android:maxLines="1"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Password -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Confirm Password -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
app:passwordToggleEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm Password"
android:inputType="textPassword"
android:maxLines="1"/>
</com.google.android.material.textfield.TextInputLayout>
<!-- Sign Up Button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnSignUp"
android:layout_width="match_parent"
android:layout_height="56dp"
android:text="SIGN UP"
android:textAllCaps="true"
android:backgroundTint="@color/primary"
android:textColor="@color/white"
app:cornerRadius="8dp"
android:layout_marginBottom="24dp"/>
<!-- Divider -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginBottom="24dp">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:background="@color/gray_light"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" OR "
android:textColor="@color/gray_medium"
android:textSize="14sp"/>
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:background="@color/gray_light"/>
</LinearLayout>
<!-- Social Login Buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginBottom="24dp">
<!-- Google Button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnGoogle"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:backgroundTint="@color/white"
android:textColor="@color/primary_text"
app:icon="@drawable/ic_google"
app:iconGravity="textStart"
app:iconSize="24dp"
app:cornerRadius="8dp"
android:text="Google"
android:outlineProvider="bounds"
android:elevation="2dp"/>
<!-- Facebook Button -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btnFacebook"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:backgroundTint="@color/facebook_blue"
android:textColor="@color/white"
app:icon="@drawable/ic_facebook"
app:iconGravity="textStart"
app:iconSize="24dp"
app:cornerRadius="8dp"
android:text="Facebook"
android:outlineProvider="bounds"
android:elevation="2dp"/>
</LinearLayout>
<!-- Login Link -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Already have an account? Log In"
android:textColor="@color/primary"
android:textSize="14sp"
android:clickable="true"
android:focusable="true"
android:id="@+id/tvLoginLink"/>
</LinearLayout>
2. Java Activity – SignUpActivity.java
package com.example.yourapp;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.FacebookAuthProvider;
public class SignUpActivity extends AppCompatActivity {
private TextInputEditText etName, etEmail, etPassword, etConfirmPassword;
private MaterialButton btnSignUp, btnGoogle, btnFacebook;
private TextView tvLoginLink;
// Firebase Auth (example)
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
// Initialize Firebase Auth
mAuth = FirebaseAuth.getInstance();
// Bind views
etName = findViewById(R.id.etName);
etEmail = findViewById(R.id.etEmail);
etPassword = findViewById(R.id.etPassword);
etConfirmPassword = findViewById(R.id.etConfirmPassword);
btnSignUp = findViewById(R.id.btnSignUp);
btnGoogle = findViewById(R.id.btnGoogle);
btnFacebook = findViewById(R.id.btnFacebook);
tvLoginLink = findViewById(R.id.tvLoginLink);
// Sign Up button click
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
attemptSignUp();
}
});
// Social login: Google (stub – replace with actual Google Sign-In)
btnGoogle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// For production, integrate Google Sign-In and then firebaseAuthWithGoogle()
Toast.makeText(SignUpActivity.this, "Google Sign-In coming soon", Toast.LENGTH_SHORT).show();
// Example: signInWithGoogle();
}
});
// Social login: Facebook (stub – replace with actual Facebook Login)
btnFacebook.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SignUpActivity.this, "Facebook Login coming soon", Toast.LENGTH_SHORT).show();
// Example: signInWithFacebook();
}
});
// Navigate to Login
tvLoginLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Start LoginActivity
startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
finish();
}
});
}
/**
* Validates inputs and attempts to create a new user with email & password.
*/
private void attemptSignUp() {
// Reset errors
((TextInputLayout) etName.getParent()).setError(null);
((TextInputLayout) etEmail.getParent()).setError(null);
((TextInputLayout) etPassword.getParent()).setError(null);
((TextInputLayout) etConfirmPassword.getParent()).setError(null);
String name = etName.getText().toString().trim();
String email = etEmail.getText().toString().trim();
String password = etPassword.getText().toString().trim();
String confirmPassword = etConfirmPassword.getText().toString().trim();
boolean cancel = false;
View focusView = null;
// Check for empty fields
if (TextUtils.isEmpty(name)) {
((TextInputLayout) etName.getParent()).setError("Name required");
focusView = etName;
cancel = true;
} else if (TextUtils.isEmpty(email)) {
((TextInputLayout) etEmail.getParent()).setError("Email required");
focusView = etEmail;
cancel = true;
} else if (!isEmailValid(email)) {
((TextInputLayout) etEmail.getParent()).setError("Invalid email");
focusView = etEmail;
cancel = true;
} else if (TextUtils.isEmpty(password)) {
((TextInputLayout) etPassword.getParent()).setError("Password required");
focusView = etPassword;
cancel = true;
} else if (!isPasswordValid(password)) {
((TextInputLayout) etPassword.getParent()).setError("Password too short (min 6)");
focusView = etPassword;
cancel = true;
} else if (TextUtils.isEmpty(confirmPassword)) {
((TextInputLayout) etConfirmPassword.getParent()).setError("Confirm password");
focusView = etConfirmPassword;
cancel = true;
} else if (!password.equals(confirmPassword)) {
((TextInputLayout) etConfirmPassword.getParent()).setError("Passwords do not match");
focusView = etConfirmPassword;
cancel = true;
}
if (cancel) {
focusView.requestFocus();
} else {
// Proceed with Firebase email/password registration
registerUserWithEmail(email, password);
}
}
private boolean isEmailValid(String email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
private boolean isPasswordValid(String password) {
return password.length() >= 6;
}
/**
* Registers a new user with email & password using Firebase Auth.
*/
private void registerUserWithEmail(String email, String password) {
// Show progress (could use a ProgressDialog)
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign up success
FirebaseUser user = mAuth.getCurrentUser();
// You can update the user's profile with the name here
// e.g., updateProfile(name);
Toast.makeText(SignUpActivity.this, "Registration successful!", Toast.LENGTH_SHORT).show();
// Navigate to main/home screen
startActivity(new Intent(SignUpActivity.this, MainActivity.class));
finish();
} else {
// If sign up fails, display a message to the user.
Toast.makeText(SignUpActivity.this, "Authentication failed: " + task.getException().getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
}
// ============ Social Login Stubs (Firebase) ============
/*
// Google Sign-In (requires GoogleSignInClient setup)
private void signInWithGoogle() {
// Start Google Sign-In intent
}
private void firebaseAuthWithGoogle(String idToken) {
AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
// Signed in
} else {
// Handle error
}
});
}
// Facebook Login (requires Facebook SDK)
private void signInWithFacebook() {
// Start Facebook Login
}
private void firebaseAuthWithFacebook(String accessToken) {
AuthCredential credential = FacebookAuthProvider.getCredential(accessToken);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
// Signed in
} else {
// Handle error
}
});
}
*/
}
Social Login Icons
Place vector drawables in res/drawable/:
ic_google.xml(Google logo)ic_facebook.xml(Facebook logo)ic_app_logo.xml(your app’s logo)
If you don’t have them, you can use Android Studio’s Vector Asset tool to import Material icons or brand logos.
4. Dependencies (build.gradle)
Add these to your app‑level build.gradle:
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.firebase:firebase-auth:22.1.2'
// For Google Sign-In
implementation 'com.google.android.gms:play-services-auth:20.6.0'
// For Facebook Login
implementation 'com.facebook.android:facebook-login:16.2.0'
}
5. Notes & Customization
- Social login – the provided code contains stubs. To make them work, follow the official Firebase guides for Google Sign-In and Facebook Login.
- Validation – currently checks for non‑empty fields, email format, password length (≥6), and matching passwords.
- Navigation – after successful sign‑up, the user is directed to
MainActivity. Change the intent as needed. - Profile update – you can call
FirebaseUser.updateProfile()to store the user’s name. - Error handling – all errors are shown as floating hints on the
TextInputLayoutfields.
