Example usage for android.widget TextView setGravity

List of usage examples for android.widget TextView setGravity

Introduction

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

Prototype

public void setGravity(int gravity) 

Source Link

Document

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

Usage

From source file:Main.java

public static void showShortToastBottom(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    TextView v = toast.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);
    toast.show();// w ww. j  av  a  2s .  com
}

From source file:Main.java

public static void showLongToastTop(Context context, int resId) {
    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 100);
    TextView v = toast.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);
    toast.show();// ww  w  .  j ava 2  s.  c o m
}

From source file:Main.java

private static TableRow generateAfiTblRow(Context context, String first, String second) {
    TableRow tr = new TableRow(context);
    tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    LayoutParams childLp = new LayoutParams(0, LayoutParams.FILL_PARENT, 1);

    TextView amount = new TextView(context);
    amount.setText(first);/*w ww.  java  2  s.c o m*/
    amount.setGravity(Gravity.CENTER);
    tr.addView(amount, childLp);

    TextView score = new TextView(context);
    score.setText(second);
    score.setGravity(Gravity.CENTER);
    tr.addView(score, childLp);

    return tr;
}

From source file:Main.java

public static TextView createTextView(Context context, String text) {
    TextView tv = new TextView(context);
    tv.setPadding(10, 10, 10, 10);//  w w  w  . j  a va2  s .co  m
    tv.setText(text);
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(24);
    tv.setTextColor(Color.RED);
    return tv;
}

From source file:Main.java

public static void setToastView(Context context, String str) {
    Toast makeText = Toast.makeText(context, "   " + str + "   ", 0);
    TextView textView = (TextView) makeText.getView().findViewById(16908299);
    if (textView != null) {
        textView.setGravity(17);
    }//from   w  w w.j a v  a  2  s.  c om
    makeText.show();
}

From source file:Main.java

public static Toast alert(Context ctx, String message) {
    Toast t = Toast.makeText(ctx, message, Toast.LENGTH_SHORT);
    TextView v = (TextView) t.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);
    t.show();/*w ww.j a  v a  2  s  .c  o  m*/

    return t;
}

From source file:Main.java

public static Toast alert(Context ctx, int nResID) {
    Toast t = Toast.makeText(ctx, nResID, Toast.LENGTH_SHORT);
    TextView v = (TextView) t.getView().findViewById(android.R.id.message);
    if (v != null)
        v.setGravity(Gravity.CENTER);
    t.show();/*from   ww w .j a va 2s. c o  m*/

    return t;
}

From source file:Main.java

/**
 * Show toast message./*from   ww  w.java 2  s .  c  om*/
 *
 * @param context Context
 * @param message Text to display
 */
public static void ShowMessage(Context context, String message) {
    if (context != null) {
        if (TOAST != null) {
            TOAST.cancel();
        }
        Toast newToast = Toast.makeText(context, message,
                message.length() < 15 ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
        TextView textView = (TextView) newToast.getView().findViewById(android.R.id.message);
        textView.setGravity(Gravity.CENTER);
        textView.setSingleLine(false);
        newToast.show();
        TOAST = newToast;
    }
}

From source file:Main.java

public static void showCenteredToast(Context context, CharSequence text, int duration) {
    Toast toast = Toast.makeText(context, text, duration);
    TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
    if (v != null) {
        v.setGravity(Gravity.CENTER);
    }//from   w  ww . ja  va2 s.c  o m
    toast.show();
}

From source file:Main.java

public static void showCenteredToast(Context context, int resId, int duration) {
    Toast toast = Toast.makeText(context, resId, duration);
    TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
    if (v != null) {
        v.setGravity(Gravity.CENTER);
    }//from  w  w w.  j  av  a2s  .  c om
    toast.show();
}