How do you display a Toast using Kotlin on Android?

前端 未结 15 2423
遇见更好的自我
遇见更好的自我 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:31

    Just to add on @nhaarman's answer --> you probably want to add the resourceId support as well

    fun Context.toast(resourceId: Int) = toast(getString(resourceId))
    fun Context.toast(message: CharSequence) = 
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
    

提交回复
热议问题