AlertUtil
Class Initialize
การเริ่มต้นใช้งาน จะมี 2 กรณีคือ ถ้าต้องการใช้ companion object function จะสามารถใช้งานได้ 1 function คือ setAlertButtonColor() แต่ถ้าต้องการจะใช้ function อื่นๆ จะต้องประกาศ object ของคลาสตามตัวอย่าง
AlertUtil(private val context: Context)
Method Overview
| Name | Description | Return |
|---|
| setAlertButtonColor() | กำหนดสีให้ปุ่มใน AlertDialog | Unit |
| createAlertBuilder() | เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ | AlertDialog.Builder |
| createAlertFromView() | เป็นการสร้าง AlertDialog จาก custom view | AlertDialog |
Method Details
fun setAlertButtonColor(dialog: AlertDialog , button : Int , hexColorString : String)
กำหนดสีให้ปุ่มใน AlertDialog
Parameters
| Name | Description | Type |
|---|
| dialog | AlertDialog ที่เราต้องการ | AlertDialog |
| button | ID ของ Button นั้น | Int |
| hexColorString | สีที่ต้องการ โดยมีรูปแบบเป็น hex color | String |
fun setAlertButtonColor(dialog: AlertDialog , button : Int , color : Int)
กำหนดสีให้ปุ่มใน AlertDialog
Parameters
| Name | Description | Type |
|---|
| dialog | AlertDialog ที่เราต้องการ | AlertDialog |
| button | ID ของ Button นั้น | Int |
| color | สีที่ต้องการโดยเอาจาก ID ของ color ใน res | Int |
fun setAlertButtonColor(dialog: AlertDialog , button : Int , colorId :Int , theme : Resources.Theme? = null)
กำหนดสีและ theme ให้ปุ่มใน AlertDialog
Parameters
| Name | Description | Type | Default |
|---|
| dialog | AlertDialog ที่เราต้องการ | AlertDialog | |
| button | ID ของ Button นั้น | Int | |
| colorId | สีที่ต้องการโดยเอาจาก ID ของ color ใน res | Int | |
| theme | Theme ของ Button ใน AlertDialog | Resources.Theme? | null |
fun createAlertBuilder(titleMsg : String , detailMsg: String) : AlertDialog.Builder
เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ
Parameters
| Name | Description | Type |
|---|
| titleMsg | หัวเรื่องของ AlertDialog | String |
| detailMsg | รายละเอียดของ AlertDialog | String |
Returns
| Type | Description |
|---|
| AlertDialog.Builder | AlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล |
fun createAlertBuilder(@StringRes titleMsgId : Int , @StringRes detailMsgId: Int) : AlertDialog.Builder
เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ
Parameters
| Name | Description | Type |
|---|
| titleMsgId | หัวเรื่องของ AlertDialog โดยเป็น ID ของ string ใน res | Int |
| detailMsgId | รายละเอียดของ AlertDialog โดยเป็น ID ของ string ใน res | Int |
Returns
| Type | Description |
|---|
| AlertDialog.Builder | AlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล |
fun createAlertBuilder(titleMsg : String , @StringRes detailMsgId: Int) : AlertDialog.Builder
เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ
Parameters
| Name | Description | Type |
|---|
| titleMsg | หัวเรื่องของ AlertDialog | String |
| detailMsgId | รายละเอียดของ AlertDialog โดยเป็น ID ของ string ใน res | Int |
Returns
| Type | Description |
|---|
| AlertDialog.Builder | AlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล |
fun createAlertBuilder(@StringRes titleMsgId : Int , detailMsg: String) : AlertDialog.Builder
เป็นการสร้าง AlertDialog.Builder โดยกำหนดค่า title และ detail ของ Alert ได้ตามต้องการ
Parameters
| Name | Description | Type |
|---|
| titleMsgId | หัวเรื่องของ AlertDialog โดยเป็น ID ของ string ใน res | Int |
| detailMsg | รายละเอียดของ AlertDialog | String |
Returns
| Type | Description |
|---|
| AlertDialog.Builder | AlertDialog.Builder ที่มี title และ detail ที่เรากำหนดไว้ สามารถไป custom ต่อได้ หรือจะ .create().show() เพื่อแสดงผล |
fun createAlertFromView(view: View) : AlertDialog
เป็นการสร้าง AlertDialog จาก custom view
Parameters
| Name | Description | Type |
|---|
| view | เป็น view ที่เรา custom เพื่อต้องการโชว์บน AlertDialog | View |
Returns
| Type | Description |
|---|
| AlertDialog | AlertDialog ที่แสดงผลตัว customview |