강의 링크 : https://youtu.be/f7_ORwhSx2E
1.
처음 생성하는 액티비티 이름을 LoginActivity 로 하여 프로젝트를 생성
2.
라이브러리 추가
GradleScripts/ build.gradle(Module:app) |
apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.example.han.management" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' compile 'com.android.volley:volley:1.0.0' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' }
|
volley는 http(네트워크 통신)과 관련된 라이브러리.
3.
액티비티 추가.
기존에 LoginActivity 에 더하여 MainActivity, RegisterActivity 두개를 추가 & 화면구성(강의에서는 relative layout으로 만들지만, 안드로이드 스튜디오가 constraintlayout으로 자동 생성하길래 그냥 그대로 만듬)
activity_login.xml |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.example.han.member.LoginActivity">
<EditText android:id="@+id/textView" android:layout_width="353dp" android:layout_height="46dp" android:ems="10" android:hint="ID" android:inputType="textPersonName" tools:layout_editor_absoluteX="16dp" tools:layout_editor_absoluteY="16dp" />
<Button android:id="@+id/loginButton" android:layout_width="354dp" android:layout_height="wrap_content" android:layout_marginTop="72dp" android:text="로그인" app:layout_constraintTop_toBottomOf="@+id/textView" tools:layout_editor_absoluteX="15dp" />
<EditText android:id="@+id/passwordText" android:layout_width="349dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:ems="10" android:hint="password" android:inputType="textPassword" app:layout_constraintTop_toBottomOf="@+id/textView" tools:layout_editor_absoluteX="16dp" />
<TextView android:id="@+id/registerButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="회원가입" android:textAppearance="@style/TextAppearance.AppCompat.Button" app:layout_constraintTop_toBottomOf="@+id/loginButton" tools:layout_editor_absoluteX="163dp" /> </android.support.constraint.ConstraintLayout>
|
activity_main.xml |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.example.han.member.MainActivity">
<TextView android:id="@+id/welcomeMessage" android:layout_width="353dp" android:layout_height="51dp" android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat.Display1" tools:layout_editor_absoluteX="16dp" tools:layout_editor_absoluteY="16dp" />
<TextView android:id="@+id/textView" android:layout_width="354dp" android:layout_height="35dp" android:layout_marginTop="8dp" android:text="아이디" android:textAppearance="@style/TextAppearance.AppCompat.Headline" app:layout_constraintTop_toBottomOf="@+id/welcomeMessage" tools:layout_editor_absoluteX="16dp" />
<TextView android:id="@+id/passwordText" android:layout_width="353dp" android:layout_height="51dp" android:layout_marginTop="8dp" android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat.Display1" app:layout_constraintTop_toBottomOf="@+id/textView2" tools:layout_editor_absoluteX="16dp" />
<TextView android:id="@+id/idText2" android:layout_width="353dp" android:layout_height="51dp" android:layout_marginTop="8dp" android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat.Display1" app:layout_constraintTop_toBottomOf="@+id/textView" tools:layout_editor_absoluteX="16dp" />
<TextView android:id="@+id/textView2" android:layout_width="346dp" android:layout_height="35dp" android:layout_marginTop="8dp" android:text="비밀번호" android:textAppearance="@style/TextAppearance.AppCompat.Headline" app:layout_constraintTop_toBottomOf="@+id/idText2" tools:layout_editor_absoluteX="16dp" /> </android.support.constraint.ConstraintLayout>
|
activity_register.xml |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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="com.example.han.member.RegisterActivity">
<EditText android:id="@+id/textView" android:layout_width="358dp" android:layout_height="44dp" android:ems="10" android:hint="id" android:inputType="textPersonName" tools:layout_editor_absoluteX="16dp" tools:layout_editor_absoluteY="18dp" />
<EditText android:id="@+id/passwordText" android:layout_width="354dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:ems="10" android:hint="pw" android:inputType="textPersonName" app:layout_constraintTop_toBottomOf="@+id/textView" tools:layout_editor_absoluteX="16dp" />
<EditText android:id="@+id/nameText" android:layout_width="353dp" android:layout_height="48dp" android:layout_marginTop="8dp" android:ems="10" android:hint="name" android:inputType="textPersonName" app:layout_constraintTop_toBottomOf="@+id/passwordText" tools:layout_editor_absoluteX="16dp" />
<EditText android:id="@+id/ageText" android:layout_width="351dp" android:layout_height="45dp" android:layout_marginTop="8dp" android:ems="10" android:hint="10" android:inputType="textPersonName" android:text=" " app:layout_constraintTop_toBottomOf="@+id/nameText" tools:layout_editor_absoluteX="16dp" />
<Button android:id="@+id/registerButton" android:layout_width="355dp" android:layout_height="41dp" android:layout_marginTop="20dp" android:text="회원가입" app:layout_constraintTop_toBottomOf="@+id/ageText" tools:layout_editor_absoluteX="15dp" /> </android.support.constraint.ConstraintLayout>
|
강의 링크 : https://youtu.be/5ZMVRKis1eI
- 각 액티비티 사이의 연결을 다룸
LoginActivity |
package com.example.han.member; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login);
EditText idText = (EditText)findViewById(R.id.idText); EditText passwordText = (EditText)findViewById(R.id.passwordText);
Button loginButton = (Button)findViewById(R.id.loginButton); TextView registerButton = (TextView)findViewById(R.id.registerButton);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override // 클릭 시 registerIntent 를 통해서 registerActivity를 실행 public void onClick(View view) { Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class); LoginActivity.this.startActivity(registerIntent );
} }); } }
|
RegisterActivity |
package com.example.han.member; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Button; import android.widget.EditText;
public class RegisterActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register);
EditText idText = (EditText)findViewById(R.id.idText); EditText passwordText = (EditText)findViewById(R.id.passwordText); EditText nameText = (EditText)findViewById(R.id.nameText); EditText ageText = (EditText)findViewById(R.id.ageText);
Button registerButton = (Button)findViewById(R.id.registerButton);
} }
|
MainActivity |
package com.example.han.member; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.EditText; import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
EditText idText = (EditText)findViewById(R.id.idText); EditText passwordText = (EditText)findViewById(R.id.passwordText); TextView welcomeMessage = (TextView)findViewById(R.id.welcomeMessage); } }
|