show Toast with Gravity - Android android.view

Android examples for android.view:Gravity

Description

show Toast with Gravity

Demo Code

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

public class Main {

  public static void showToast(Context context, String message, int gravity) {
    if (context == null || TextUtils.isEmpty(message)) {
      return;/*from   w w  w.ja  va  2s .c o m*/
    }

    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(gravity, 0, 0);
    toast.show();
  }

  public static void showToast(Context context, String message) {
    showToast(context, message, Gravity.BOTTOM);
  }
}

Related Tutorials