Created
July 22, 2021 03:37
-
-
Save LongClipeus/c1087668d1464d25a1c03d053eaa7fe5 to your computer and use it in GitHub Desktop.
custom toast in kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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