π§ Explanation:
Toast.makeText()
is used to display short messages to the user.- The first parameter (
this
) is the Context β in an Activity, just usethis
; in a Fragment, userequireContext()
orcontext
. - The second parameter is the message string to display.
- The third parameter is the duration:
Toast.LENGTH_SHORT
(about 2 seconds)Toast.LENGTH_LONG
(about 3.5 seconds)
π Example Usage in Activity:
β Tips
- You can also use
Toast(requireContext(), "Message", Toast.LENGTH_SHORT)
in Fragments. - For custom Toasts, you can inflate your own layout using
LayoutInflater
.
Pingback: π Welcome to 7SoftSky Developer β Our Mission, Vision & Passion - 7SoftSky Developers