Android UI How to - Alert with Toast








Question

We would like to know how to alert with Toast.

Answer

/* w  w  w. jav  a2  s  . c  om*/
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class Main {

  public static void make(Context context, String msg) {
    Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.show();
  }

}