Thursday, January 2, 2014

Android: Toasts

Android provides the possibilty to display so called Toasts - messages, which appear on the screen for a short time and then disappear, which looks like this:


We create a toast with the class Toast and pass the current Activity, the string to be displayed as well as the desired duration over to the creation method . For the duration we have to use the enumeration ToastLength, which contains Short and Long.
With the function SetGravity() we can set the toast's gravity as well as its offset.
With Show() we eventually display the toast:

Toast toast = Toast.MakeText(this, "Toast", ToastLength.);
toast.SetGravity(GravityFlags.Top|GravityFlags.Left, 100, 260);
toast.Show();

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete