Example usage for android.widget TextView setPadding

List of usage examples for android.widget TextView setPadding

Introduction

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

Prototype

@Override
public void setPadding(int left, int top, int right, int bottom) 

Source Link

Usage

From source file:Main.java

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

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   ww  w .  j  a v a2 s.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:cn.foxnickel.listentome.view.ViewUtil.java

public static View getWordsView(Context context, String word, @ColorRes int color, boolean isTextSelectable) {
    TextView tv = new TextView(context);
    tv.setTextColor(ContextCompat.getColor(context, color));
    tv.setPadding(0, 6, 0, 6);
    tv.setTextSize(16);/*w  w w  .j a  v a2 s .  co m*/
    tv.setTextIsSelectable(isTextSelectable);
    tv.setGravity(Gravity.LEFT);
    tv.setText(word);
    return tv;
}

From source file:com.nma.util.sdcardtrac.SearchableActivity.java

public static int getTextHeight(Context context, CharSequence text, int textSize, int deviceWidth) { //, Typeface typeface,int padding) {
    TextView textView = new TextView(context);
    textView.setPadding(0, 0, 0, 0);
    textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
    textView.setText(text, TextView.BufferType.SPANNABLE);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);
    return textView.getMeasuredHeight();
}

From source file:ca.rmen.android.scrumchatter.chart.ChartUtils.java

static void addLegendEntry(Context context, ViewGroup legendView, String name, int color) {
    TextView memberLegendEntry = new TextView(context);
    memberLegendEntry.setText(name);//from  www. j  a va 2s .c  o m
    memberLegendEntry.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    memberLegendEntry.setPadding(0, 0,
            context.getResources().getDimensionPixelSize(R.dimen.chart_legend_entry_padding), 0);

    final Drawable icon;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square);
        memberLegendEntry.setTextColor(color);
    } else {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square).mutate();
        DrawableCompat.setTint(icon, color);
    }
    memberLegendEntry.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    legendView.addView(memberLegendEntry);
}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param c the Context/*w w  w. ja  v a  2  s. c o m*/
 * @return the about dialog
 */
public static Dialog getAbout(final Context c) {
    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle(R.string.about);

    TextView tv = new TextView(c);
    int pad = (Util.dpToPx(c, 10));
    tv.setPadding(pad, pad, pad, pad);

    try {
        tv.setText(R.string.about_text);
        tv.append(c.getString(R.string.app_version,
                c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName));
        tv.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (NameNotFoundException e1) {
        // should not happen as the app is definitely installed when
        // seeing the dialog
        e1.printStackTrace();
    }
    builder.setView(tv);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    return builder.create();
}

From source file:com.moubry.worthwatching.ui.BaseActivity.java

public static AlertDialog createWhatsNewAlert(Context context) {
    final TextView message = new TextView(context);
    final SpannableString s = new SpannableString(context.getText(R.string.whats_new_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setPadding(10, 10, 10, 10);
    message.setText(s);/*from   w  w w  .j av  a  2s .com*/
    message.setLinkTextColor(context.getResources().getColor(R.color.blue));
    message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    message.setMovementMethod(LinkMovementMethod.getInstance());

    return new AlertDialog.Builder(context).setTitle(R.string.title_whats_new).setCancelable(true)
            .setPositiveButton("OK", null).setView(message).create();
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void addImgLinkText(final Context context, ArrayList<View> views, final String url,
        LinearLayout.LayoutParams params) {
    final TextView textView = new TextView(context);
    textView.setTextColor(Color.BLUE);
    textView.setLayoutParams(params);//from  w  w w.  j a v a2s  .  co  m
    textView.setText("View image");
    textView.setTextSize(getTextSize(context));
    textView.setPadding(3, 3, 3, 3);
    textView.setTag(url);
    textView.setClickable(true);
    setupOnLinkClick(context, url, textView);
    views.add(textView);
}

From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher_no_bg));
    layout.addView(logo);/*from  ww w .  java2  s.  c o  m*/

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:csic.ceab.movelab.beepath.Util.java

/**
 * Displays a brief message on the phone screen. Taken from Human Mobility
 * Project code written by Chang Y. Chung and Necati E. Ozgencil.
 * //from  ww  w . j  a  v a 2s.  c  o m
 * @param context
 *            Interface to application environment
 * @param msg
 *            The message to be displayed to the user
 */
public static void toast(Context context, String msg) {

    TextView tv = new TextView(context);
    tv.setText(msg);
    Drawable bknd = context.getResources().getDrawable(R.drawable.white_border);
    tv.setBackgroundDrawable(bknd);
    tv.setPadding(20, 20, 20, 20);
    tv.setTextSize(20);

    Toast t = new Toast(context);
    t.setDuration(Toast.LENGTH_LONG);
    t.setView(tv);
    t.show();
}