Alert

AlertUtil

Class Initialize

การเริ่มต้นใช้งาน จะมี 2 กรณีคือ ถ้าต้องการใช้ companion object function จะสามารถใช้งานได้ 1 function คือ setAlertButtonColor() แต่ถ้าต้องการจะใช้ function อื่นๆ จะต้องประกาศ object ของคลาสตามตัวอย่าง

AlertUtil(private val context: Context) 

Method Overview

NameDescriptionReturn
setAlertButtonColor()กำหนดสีให้ปุ่มใน AlertDialogUnit
createAlertBuilder()เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการAlertDialog.Builder
createAlertFromView()เป็นการสร้าง AlertDialog จาก custom viewAlertDialog

Method Details

fun setAlertButtonColor(dialog: AlertDialog , button : Int , hexColorString : String)

กำหนดสีให้ปุ่มใน AlertDialog

Parameters

NameDescriptionType
dialogAlertDialog ที่เราต้องการAlertDialog
buttonID ของ Button นั้นInt
hexColorStringสีที่ต้องการ โดยมีรูปแบบเป็น hex colorString
fun setAlertButtonColor(dialog: AlertDialog , button : Int , color : Int)

กำหนดสีให้ปุ่มใน AlertDialog

Parameters

NameDescriptionType
dialogAlertDialog ที่เราต้องการAlertDialog
buttonID ของ Button นั้นInt
colorสีที่ต้องการโดยเอาจาก ID ของ color ใน resInt
fun setAlertButtonColor(dialog: AlertDialog , button : Int , colorId :Int , theme : Resources.Theme? = null)

กำหนดสีและ theme ให้ปุ่มใน AlertDialog

Parameters

NameDescriptionTypeDefault
dialogAlertDialog ที่เราต้องการAlertDialog
buttonID ของ Button นั้นInt
colorIdสีที่ต้องการโดยเอาจาก ID ของ color ใน resInt
themeTheme ของ Button ใน AlertDialogResources.Theme?null
fun createAlertBuilder(titleMsg : String , detailMsg: String) : AlertDialog.Builder

เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ

Parameters

NameDescriptionType
titleMsgหัวเรื่องของ AlertDialogString
detailMsgรายละเอียดของ AlertDialogString

Returns

TypeDescription
AlertDialog.BuilderAlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล
fun createAlertBuilder(@StringRes titleMsgId : Int , @StringRes detailMsgId: Int) : AlertDialog.Builder

เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ

Parameters

NameDescriptionType
titleMsgIdหัวเรื่องของ AlertDialog โดยเป็น ID ของ string ใน resInt
detailMsgIdรายละเอียดของ AlertDialog โดยเป็น ID ของ string ใน resInt

Returns

TypeDescription
AlertDialog.BuilderAlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล
fun createAlertBuilder(titleMsg : String ,  @StringRes detailMsgId: Int) : AlertDialog.Builder

เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ

Parameters

NameDescriptionType
titleMsgหัวเรื่องของ AlertDialogString
detailMsgIdรายละเอียดของ AlertDialog โดยเป็น ID ของ string ใน resInt

Returns

TypeDescription
AlertDialog.BuilderAlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล
fun createAlertBuilder(@StringRes titleMsgId : Int , detailMsg: String) : AlertDialog.Builder

เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ

Parameters

NameDescriptionType
titleMsgIdหัวเรื่องของ AlertDialog โดยเป็น ID ของ string ใน resInt
detailMsgรายละเอียดของ AlertDialogString

Returns

TypeDescription
AlertDialog.BuilderAlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล
fun createAlertFromView(view: View) : AlertDialog

เป็นการสร้าง AlertDialog จาก custom view

Parameters

NameDescriptionType
viewเป็น view ที่เรา custom เพื่อต้องการโชว์บน AlertDialogView

Returns

TypeDescription
AlertDialogAlertDialog ที่แสดงผลตัว customview