Search code examples
androidandroid-ktx

Where is the KTX toast extension function?


I have learned from this article Even Sweeter Android development with Android KTX (https://www.kotlindevelopment.com/even-sweeter-android-ktx-kotlin/) that Android toast can be simplified using KTX from

Toast.makeText(context, R.string.toast_message, Toast.LENGTH_SHORT).show()

to

toast(R.string.toast_message)

I wanted to try it in my project but I couldn't find it in androidx.core:core-ktx:1.0.0. So in which dependency is this extension function?


Solution

  • Add this

    api "org.jetbrains.anko:anko-commons:0.10.1"
    

    and use it like

    toast(R.string.toast_message)
    

    or

    context.toast(R.string.toast_message)