Example usage for android.widget Toast setGravity

List of usage examples for android.widget Toast setGravity

Introduction

In this page you can find the example usage for android.widget Toast setGravity.

Prototype

public void setGravity(int gravity, int xOffset, int yOffset) 

Source Link

Document

Set the location at which the notification should appear on the screen.

Usage

From source file:net.ben.subsonic.androidapp.util.Util.java

public static void toast(Context context, String message) {
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();/*  ww w.j  av a2s  .  com*/
}

From source file:net.ben.subsonic.androidapp.util.Util.java

public static void toast(Context context, int messageId, boolean shortDuration) {
    Toast toast = Toast.makeText(context, messageId, shortDuration ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();// w w w . j a v  a  2s  .co m
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static Toast showLongToast(final Context context, final String text) {
    T.UI();//from  w w w. j a  va  2  s. c o  m
    final Toast t = Toast.makeText(context, text, Toast.LENGTH_LONG);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
    return t;
}

From source file:MainActivity.java

public void showToast(View view) {
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast_custom, null);
    ((TextView) layout.findViewById(android.R.id.message)).setText("Custom Toast");
    Toast toast = new Toast(this);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);//w w  w . j a  v  a2s  .c om
    toast.show();
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void upperLeft(View v) {
    Toast toast = Toast.makeText(this, "Upper Left!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
    toast.show();// ww  w . ja v a2 s .  c  o m
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void upperRight(View v) {
    Toast toast = Toast.makeText(this, "Upper Right!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 0);
    toast.show();//from w w  w  .j av  a 2  s. c o m
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void bottomRight(View v) {
    Toast toast = Toast.makeText(this, "Bottom Right!", Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT, 0, 0);
    toast.show();//ww  w.j a v  a2  s. c  o  m
}

From source file:com.manning.androidhacks.hack016.MainActivity.java

public void bottomLeft(View v) {
    Toast toast = Toast.makeText(this, "Bottom Left!", Toast.LENGTH_SHORT);

    toast.setGravity(Gravity.BOTTOM | Gravity.LEFT, 0, 0);
    toast.show();/*from  w w  w . j a va2s.c o m*/
}

From source file:com.xargsgrep.portknocker.asynctask.KnockerAsyncTask.java

private void showToast(String text) {
    Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.show();//w w w.  java  2 s. c  o  m
}

From source file:com.paad.wifi4us.ShareActionProvider.java

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    //mContext.getMenuInflater().inflate(R.menu.actionbar_meau, subMenu);
    subMenu.add(0, 0, 0, "back").setIcon(R.drawable.ic_back)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override/* w  w w .  j a  va2  s . c  o m*/
                public boolean onMenuItemClick(MenuItem item) {
                    Toast toast = Toast.makeText(mContext, "click back sub-menu", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                    return true;
                }

            });
    subMenu.add(0, 0, 0, "more").setIcon(R.drawable.ic_more)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    Toast toast = Toast.makeText(mContext, "click more sub-menu", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                    return true;
                }

            });
    super.onPrepareSubMenu(subMenu);
}