How do you display a Toast using Kotlin on Android?

前端 未结 15 2226
遇见更好的自我
遇见更好的自我 2021-01-30 16:08

In different Kotlin examples for Android I see toast("Some message...") or toastLong("Some long message"). For example:



        
15条回答
  •  长发绾君心
    2021-01-30 16:21

    It's actually a part of Anko, an extension for Kotlin. Syntax is as follows:

    toast("Hi there!")
    toast(R.string.message)
    longToast("Wow, such a duration")
    

    In your app-level build.gradle, add implementation "org.jetbrains.anko:anko-common:0.8.3"

    Add import org.jetbrains.anko.toast to your Activity.

提交回复
热议问题