Here is extension of toast for activity or fragment
fun showToast(context: Context,@StringRes string : Int, duration: Int = Toast.LENGTH_SHORT){
Toast.makeText(context,string,duration).show()
}
inline fun Context.toast(message:()->String){
Toast.makeText(this, message() , Toast.LENGTH_LONG).show()
}
inline fun Fragment.toast(message: () -> String, duration: () -> Int = { Toast.LENGTH_LONG }){
Toast.makeText(this.context,message(),duration()).show()
}
inline fun AppCompatActivity.toast(message: () -> String, duration: () -> Int = { Toast.LENGTH_LONG }){
Toast.makeText(this.applicationContext,message(),duration()).show()
}
If you want simple toast just call first method both fragment and activity
showToast(yourContext,"your message") or showToast(yourContext,"your message",1200L)
Or
toast {
"Your message"
}
Or
toast({"your message"}) or toast({"your messge"},{your duration = 1200L})