To show the working and to demonstrate how toast and snackbar pop ups to user screen.
The Toast Message is a simple pop-up message that displays a short string of texts to the user.
Toast toast = Toast.makeText(getApplicationContext(),"Hello, This is a Toast.",toastDuration);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
LayoutInflater layoutInflater = getLayoutInflater();
View viewLayout = layoutInflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast_layout));
TextView textView = viewLayout.findViewById(R.id.customToast_text);
textView.setText(R.string.text_show_custom_toast_text);
Toast toast = new Toast(getApplicationContext());
toast.setDuration(toastDuration);
toast.setGravity(Gravity.BOTTOM,0,50);
toast.setView(viewLayout);
toast.show();
To show custom toast remember to make a xml layout and inflate using this piece of code
LayoutInflater layoutInflater = getLayoutInflater();
View viewLayout = layoutInflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast_layout));
Google recommends that developers use the snackbar.
Snackbar snackbar = Snackbar.make(view,"Follow Me On Github,Thank You.",Snackbar.LENGTH_LONG);
snackbar.show();
Snackbar.make(view,"Follow me On Github, Thanks!!",Snackbar.LENGTH_LONG)
.setAction("Ok !", new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Thank you, Stay Connected.", Toast.LENGTH_SHORT).show();
}
})
.setActionTextColor(Color.BLUE)
.show();
Twitter 🐦