app / mainfests / AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UITest1"
tools:targetApi="30">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
app / java / com.bpdev.uitest1 / MainActivity.java
package com.bpdev.uitest1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
TextView txtTitle;
EditText editNames;
EditText editPassword;
EditText editEmail;
Button btnSave;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtTitle = findViewById(R.id.textView);
editNames = findViewById(R.id.editNames);
editPassword = findViewById(R.id.editPassword);
editEmail = findViewById(R.id.editEmail);
btnSave = findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// 1. 유저가 입력한 이름을 가져온다.
String name = editNames.getText().toString().trim();
Log.i("UITest1 MAIN", name );
// 2. 유저가 입력한 비밀번호 가져온다.
String password = editPassword.getText().toString().trim();
Log.i("UITest1 MAIN", password );
// 3. 유저가 입력한 이메일 가져온다.
String email = editEmail.getText().toString().trim();
Log.i("UITest1 MAIN", email );
// 4. 데이터가 없을 경우 유저에게 알려줘야 한다. Toast
if ( name.isEmpty() || password.isEmpty() || email.isEmpty() ) {
// Toast.makeText(MainActivity.this, "필수 항목을 모두 입력해 주세요.", Toast.LENGTH_SHORT).show();
Snackbar.make(btnSave, "필수 항목 모두 입력해주세요!", Snackbar.LENGTH_LONG).show();
return;
}
// 정상이니까, 네트워크로 데이터를 보내준다!
}
});
}
}
app / res / layout / activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="8dp"
android:background="#2196F3"
android:gravity="bottom|center"
android:padding="30dp"
android:shadowColor="#3F51B5"
android:text="안녕하세요"
android:textColor="#FFFFFF"
android:textSize="34sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:id="@+id/editNames"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="224dp"
android:layout_marginEnd="60dp"
android:ems="10"
android:hint="이름 입력"
android:inputType="text"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:privateImeOptions="defaultInputMode=korean"
/>
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="300dp"
android:layout_marginEnd="60dp"
android:ems="10"
android:hint="비밀번호 입력"
android:inputType="textPassword"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="376dp"
android:layout_marginEnd="60dp"
android:ems="10"
android:hint="e-mail 주소 입력"
android:inputType="textEmailAddress"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:privateImeOptions="defaultInputMode=english"
/>
<Button
android:id="@+id/btnSave"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="29dp"
android:layout_marginEnd="60dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editEmail" />
</androidx.constraintlayout.widget.ConstraintLayout>
미리보기 화면
app / Gradle Scripts / build.gradle (module :app)
plugins {
id 'com.android.application'
}
android {
namespace 'com.bpdev.uitest1'
compileSdk 33
defaultConfig {
applicationId "com.bpdev.uitest1"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}