Skip to content

Instantly share code, notes, and snippets.

@LongClipeus
Created July 22, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LongClipeus/c1087668d1464d25a1c03d053eaa7fe5 to your computer and use it in GitHub Desktop.
Save LongClipeus/c1087668d1464d25a1c03d053eaa7fe5 to your computer and use it in GitHub Desktop.
custom toast in kotlin
fun showToastGreen(context: Context, message: String) {
val toast: Toast = Toast.makeText(context, "", Toast.LENGTH_LONG)
val view = toast.view
view.background.setColorFilter(
ContextCompat.getColor(context, R.color.green_dark),
PorterDuff.Mode.SRC_IN
)
val text = view.findViewById<TextView>(android.R.id.message)
text.setTextColor(ContextCompat.getColor(context, R.color.white))
text.text = message
text.gravity = Gravity.CENTER
toast.setGravity(Gravity.TOP, 0, 250)
toast.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment