Android KTX is a collection of Kotlin programming language lines that have been released to help the Dolopers Coding Android apps. With the help of these exins, the volume of the code will be reduced on the one hand and the programming on the other will be more attractive for Android. Google has promised to provide a series of supplementary APIs in the future, depending on the amount of other dollar cooperation and feedback received by them.
In the preview version, the Android KTX offers an API layer as well as an Android Support Library, which is also available in GateHeb. Google has promised to release other parts of Android KTX, which covers the Android Support Library Support Library, in the coming versions of these exins. In order to better understand this, we will consider the code written in Kathleen:
view.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
viewTreeObserver.removeOnPreDrawListener(this)
actionToBeTriggered()
return true
}
})
Now we have done the same performance using Android KTX:
view.doOnPreDraw {
actionToBeTriggered()
}
The method of using these exins is that after the project’s SYNC phase, the relevant exins are automatically displayed in the AutoComplete List of Development Environment (similar to other commands) and by selecting each of them, the Import command will be added to the code.
Google has pointed out that the APIs will probably change during the preview period! In other words, the dualopers should not use these APIs in real projects because the major changes are likely to be pre -sustained. Whenever the version of the API reaches stable and Google has confirmed it, the Dolopers can safely use Android KTX as part of the Android Support Library.
Method of using Android KTX
In order to use Android KTX, you can simply add the following code to your project build.gradle:
repositories {
google()
}
dependencies {
implementation 'androidx.core:core-ktx:0.1'
}
From now on, wherever you intend to use these extons, you just need to take them.
It should also be noted that the name of the Android KTX packages starts with AndroidX. According to Google, the phrase will also be used for the name of the future Support Library packages. The difference in the names that start with Android.* Or Androidx.* Will determine the difference between the versions of the used APIs, which will be effective for downtopers working on different versions of Android.