Android KTX คืออะไร ?
คือ เป็นชุดของ API สำหรับการพัฒนา Android application ด้วยภาษา Kotlin
ที่อยู่บน Android framework และ Support library ต่าง ๆ
มีเป้าหมายเพื่อ
ให้สามารถเขียน Kotlin ถูกต้องและกระชับตามหลักของภาษา (Less code, More fun)
ดังนั้นมาลองใช้งานกันดู
เริ่มด้วยการติดตั้ง Library เข้าไปใน project
repositories { google() } dependencies { implementation 'androidx.core:core-ktx:0.1' }
โดยใน Android KTX library นั้นครอบคลุมหลายส่วนเลย เช่น
- Graphic
- Annimation
- Content
- Database
- Network
- Text
- Time
- View
ลองใช้งานตามตัวอย่างหน่อยสิ
คำอธิบาย
ใช้ package เป็น androidx.* นะ นั่นคือแยกออกมาจาก android โดยสิ้นเชิง
โดย library ชุดนี้มี method ทั้งหมด 527 method
และในอนาคตของทีมพัฒนาคือ นำ Android KTX ไปใส่ใน Android Suport Library ต่อไป
ดังนั้นลองใช้เถอะนะ
Reference Websites
https://android-developers.googleblog.com/2018/02/introducing-android-ktx-even-sweeter.html
https://medium.com/exploring-android/exploring-ktx-for-android-13a369795b51