How to display/show a Toast in Android?
Android Toast is used to display a message for the short interval on the screen .A toast contains a message which is displayed and disappears shortly notifying the user.
Simple Toast can be shown like this.
Toast.makeText(context,"CoderzPassion",Toast.LENGTH_SHORT).show();
Parameters: –
- Context
- Text message
- Duration of toast can be short, long or customised in milliseconds like below.
Toast.makeText(context,"CoderzPassion",3000).show();
Customising the Toast
Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show();
other way
Toast toast=Toast.makeText(MainActivity.this,"",3000); toast.setGravity(Gravity.CENTER,0,0); toast.show();