X

Toast

Toast:
To display some message to the user, we use Toast messaging in Android. For example, while filling a registration form, if the user misses filling some fields, we need to validate the form and show some information to the user to fill.

 

Syntax:
Toast.makeText(Context, message, duration).show();

Context – represents current screen context
Ex: Activity
Message – any message in String
Duration – We have 2 duration constants here

Toast.LENGTH_SHORT – To show upto 3 seconds
Toast.LENGTH_LONG – To show upto 6 seconds

Ex:
Toast.makeText(DemoActivity.this, “Hello Hyderabad”, Toast.LENGTH_LONG).show();

Comments are closed.