ColorUtil
Method Overview
| Name | Description | Return |
|---|
| getColorWithColorID() | เป็นการแสดงสี จาก color ID ใน res | ColorStateList |
| getTransparentHexColorFromHexColor() | เป็นการ Return สีที่ถูก transparent จากสีเดิม | Int |
| getTransparentHexColorStringFromHexColor() | เป็นการ Return String สีที่เป็นรูปแบบ hex color ที่รวมการ transparent แล้ว | String |
Method Details
fun getColorWithColorID(context : Context , colorId : Int) : ColorStateList
เป็นการแสดงสี จาก color ID ใน res เช่น ColorUtil.getColorWithColorID(context,R.id.colorPrimary)
Parameters
| Name | Description | Type |
|---|
| context | context ของ fragment หรือ activity ที่จะใช้งาน | Context |
| colorId | id ของ color ใน res ที่ต้องการ | Int |
Returns
| Type | Description |
|---|
| ColorStateList | Return ColorStateList ของสีจาก ID ของ color ใน res นำไปใช้แสดงสีได้เลย |
fun getTransparentHexColorFromHexColor(hexColor : String , transparentValue : String = "FF") : Int
เป็นการ Return สีที่ถูก transparent จากสีเดิม เช่น สีเดิมที่ต้องการ #3700B3 และ transparent ที่ต้องการ #80 หรือ 80 ผลลัพธ์ได้ออกเป็น #803700B3 แต่ได้จะทำการแปลงค่า hex String ออกมาให้อยู่ในรูปของ Int ทำให้สามารถแสดงสีได้ทันที
Parameters
| Name | Description | Type | Default |
|---|
| hexColor | สีต้นแบบที่ต้องการเป็นรูปแบบ hex color | String | |
| transparentValue | ค่า transparent ที่ต้องการ | String | “FF” |
Returns
| Type | Description |
|---|
| Int | Return Int ของสีที่ทำการรวม transparent จาก hex color แล้ว |
fun getTransparentHexColorStringFromHexColor(hexColor : String , transparentValue : String = "FF") : Int
เป็นการ Return String สีที่เป็นรูปแบบ hex color ที่รวมการ transparent แล้ว เช่น สีเดิมที่ต้องการ #3700B3 และ transparent ที่ต้องการ #80 หรือ 80 ผลลัพธ์ได้ออกเป็น #803700B3
Parameters
| Name | Description | Type | Default |
|---|
| hexColor | สีต้นแบบที่ต้องการเป็นรูปแบบ hex color | String | |
| transparentValue | ค่า transparent ที่ต้องการ | String | “FF” |
Returns
| Type | Description |
|---|
| String | เป็นการ Return String สีที่เป็นรูปแบบ hex color ที่รวมการ transparent แล้ว |