티스토리 뷰
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"
android:layout_gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/btnShow"
android:textAllCaps="false"
android:text="Alert"
android:textSize="30dp"
android:textStyle="bold"
android:background="#FFBBBB"
android:layout_width="200dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
lateinit var alertDialog: AlertDialog
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
alertDialog = AlertDialog.Builder(applicationContext)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "OK", Toast.LENGTH_SHORT).show()
}
})
.setNegativeButton("Cancel", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "Cancel", Toast.LENGTH_SHORT).show()
}
})
.setNeutralButton("Neutral", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "Neutral", Toast.LENGTH_SHORT).show()
}
})
.create()
btnShow.setOnClickListener {
alertDialog.show()
}
}
}
MainActivity.kt
package com.jwsoft.kotlinproject
import android.content.DialogInterface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
lateinit var alertDialog: AlertDialog
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
alertDialog = AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "OK", Toast.LENGTH_SHORT).show()
}
})
.setNegativeButton("Cancel", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "Cancel", Toast.LENGTH_SHORT).show()
}
})
.setNeutralButton("Neutral", object: DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface?, which: Int) {
Toast.makeText(applicationContext, "Neutral", Toast.LENGTH_SHORT).show()
}
})
.create()
btnShow.setOnClickListener {
alertDialog.show()
}
}
}
alertDialog = AlertDialog.Builder(applicationContext) 에서
alertDialog = AlertDialog.Builder(true) 로 수정
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] MVVM (0) | 2020.07.21 |
---|---|
[Kotlin] RecyclerView + ItemClickListener + ItemLongClickListener (0) | 2020.07.21 |
[Kotlin] Room (0) | 2020.07.21 |
[Kotlin] SQLite + Singleton Pattern (0) | 2020.07.18 |
[Kotlin] Intent (0) | 2020.07.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- ArrayList
- coroutine
- recyclerview
- 혀가 길지 않은 개발자
- JSONArray
- View
- ViewPager2
- 자바
- Intent
- handler
- CoordinatorLayout
- Android
- James Kim
- activity
- Design Pattern
- java
- ViewModel
- Vue.js #Vue.js + javascript
- XML
- fragment
- Livedata
- 코틀린
- JSONObject
- 안드로이드
- MVVM
- TabLayout
- Architecture Pattern
- Kotlin
- 안드로이드 #코틀린 #Android #Kotlin
- DataBinding
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함