List of usage examples for android.view Gravity CENTER
int CENTER
To view the source code for android.view Gravity CENTER.
Click Source Link
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();/* w w w . ja va2 s.c om*/ }
From source file:Main.java
/** * Make long toast./* w w w .ja va 2s.com*/ * * @param ctx the ctx * @param message the message */ public static void makeLongToast(Context ctx, String message) { if (ctx != null && message != null) { Toast toast = Toast.makeText(ctx, message, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 50); toast.show(); } }
From source file:Main.java
public static void showToast(Context context, int resId) { Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();/*from w ww. j a v a 2 s . c om*/ }
From source file:Main.java
public static void showLToast(Context context, int resId) { Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG); ;/* w w w . j a v a2 s . c om*/ toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
From source file:Main.java
@SuppressWarnings("deprecation") public static void clipDrawable(final View image, Drawable drawable, boolean isActivated) { if (drawable == null) { return;//from w ww . j ava2s. c o m } if (isActivated) { final ClipDrawable scaleDrawable = new ClipDrawable(drawable, Gravity.CENTER, ClipDrawable.HORIZONTAL | ClipDrawable.VERTICAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { image.setBackground(scaleDrawable); } else { image.setBackgroundDrawable(scaleDrawable); } image.setBackgroundDrawable(scaleDrawable); ValueAnimator animator = ValueAnimator.ofInt(0, 10000); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scaleDrawable.setLevel((Integer) animation.getAnimatedValue()); } }); animator.start(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { image.setBackground(null); } else { image.setBackgroundDrawable(null); } } }
From source file:Main.java
public static void showOkDialog(String title, String msg, Activity act) { AlertDialog.Builder dialog = new AlertDialog.Builder(act); if (title != null) { TextView dialogTitle = new TextView(act); dialogTitle.setText(title);/*from w ww .ja v a 2s .co m*/ dialogTitle.setPadding(10, 10, 10, 10); dialogTitle.setGravity(Gravity.CENTER); dialogTitle.setTextColor(Color.WHITE); dialogTitle.setTextSize(20); dialog.setCustomTitle(dialogTitle); } if (msg != null) { dialog.setMessage(msg); } dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); AlertDialog dlg = dialog.show(); TextView messageText = (TextView) dlg.findViewById(android.R.id.message); messageText.setGravity(Gravity.CENTER); }
From source file:Main.java
/** * Creates a custom {@link Toast} with a custom layout View * // w ww . j av a 2 s.co m * @param context * the context * @param resId * the custom view * @return the created {@link Toast} */ public static Toast makeCustomToast(Context context, int resId) { View view = LayoutInflater.from(context).inflate(resId, null); Toast t = new Toast(context); t.setDuration(Toast.LENGTH_SHORT); t.setView(view); t.setGravity(Gravity.CENTER, 0, 0); return t; }
From source file:Main.java
/** * Posts a new Toast//from w w w . j ava 2 s . c o m * * @param context * @param text * @param duration */ public static void postToast(Context context, CharSequence text, int duration) { postToast(context, text, duration, Gravity.CENTER); }
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 w w . j a va2s . 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 void showToast(Context context, int resId, int time) { Toast toast = Toast.makeText(context, resId, time); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();// w w w. ja v a 2 s . c o m }