코린이 탈출기
chapter 4.2 - 실습해보기 본문
화면과 같이 만들어 보고 비교해보기
아이디 "sohee@naver.com"와 비밀번호 "0000"입력 시 토스트에 "관리자 입니다" 띄우기
만일 둘 중 하나라도 다르다면 토스토에 "로그인 실패" 띄우기

코드내용
xml코드
<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"
android:padding="10dp"
tools:context=".Test">
<ImageView
android:id="@+id/loginImg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/idTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="아이디"
android:textSize="20sp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/loginImg"
app:layout_constraintLeft_toLeftOf="parent"/>
<EditText
android:id="@+id/idEdt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="이메일 형식으로 입력"
android:inputType="textEmailAddress"
app:layout_constraintTop_toBottomOf="@id/idTxt"/>
<TextView
android:id="@+id/pwTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="비밀번호"
android:textSize="20sp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/idEdt"
app:layout_constraintLeft_toLeftOf="parent"/>
<EditText
android:id="@+id/pwEdt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="8자 이상"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@id/pwTxt"/>
<Button
android:id="@+id/loginBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="로그인"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity 코드
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Btn.setOnClickListener {
val id = edtId.text.toString()
val password = edtPassword.text.toString()
if (id == "sohee@naver.com" && password == "0000") {
Toast.makeText(this, "관리자입니다.", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "로그인 실패", Toast.LENGTH_SHORT).show()
}
}
}
}'인터넷 강의 > 클래스101 - 비전공자들을 위한 나만의 안드로이드 앱 만들기' 카테고리의 다른 글
| chapter 4.4 - 코드 깔끔하게 작성하기 - 카멜 표기법 (1) | 2021.04.22 |
|---|---|
| chapter 4.3 - 출력할 문구 가공하기 - kotlin의 String 가공 (0) | 2021.04.22 |
| chapter 4.1 - 코틀린으로 UI 속성 변경해 보기 - Text (0) | 2021.04.22 |
| chapter 3.4 - 코틀린 기초 문법 - 조건문 이해하기 (0) | 2021.04.21 |
| chapter 3.3 - 코틀린 기초 문법 - 변수 / 변수 만들기 (0) | 2021.04.21 |
Comments