List of usage examples for android.widget TextView getPaint
public TextPaint getPaint()
From source file:com.ouyangzn.github.utils.UiUtils.java
/** * textView//from w ww . j av a 2 s .com * * @param textView TextView */ public static void addUnderLine(TextView textView) { textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); }
From source file:Main.java
public static int getTextViewLineCount(TextView textView, String text, int maxWidth) { if (textView == null) return 0; int index = 0; int lineCount = 0; TextPaint paint = textView.getPaint(); while (index < text.length()) { index += paint.breakText(text, index, text.length(), true, maxWidth, null); lineCount++;/*from www .j a va 2 s. com*/ } return lineCount; }
From source file:Main.java
public static void setTabWidgetTitle(Context context, TabWidget tabWidget, int size, int color) { TextView tv = null; for (int i = 0, count = tabWidget.getChildCount(); i < count; i++) { tv = ((TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title)); tv.setTextSize(size);//from w w w . j ava 2 s . c o m tv.getPaint().setFakeBoldText(false); tv.setTextColor(context.getResources().getColorStateList(color)); } }
From source file:Main.java
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) { int drawablePadding = view.getCompoundDrawablePadding(); int ratio = 1; float total;//from w w w . j av a 2 s . c o m switch (gravity) { case Gravity.END: ratio = -1; case Gravity.START: total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight(); canvas.translate(ratio * (view.getWidth() - total) / 2, 0); break; case Gravity.BOTTOM: ratio = -1; case Gravity.TOP: Paint.FontMetrics fontMetrics = view.getPaint().getFontMetrics(); total = fontMetrics.descent - fontMetrics.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom(); canvas.translate(0, ratio * (view.getHeight() - total) / 2); break; } }
From source file:Main.java
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) { int drawablePadding = view.getCompoundDrawablePadding(); int ratio = 1; float total;// w w w .j a v a2 s . co m switch (gravity) { case Gravity.RIGHT: ratio = -1; case Gravity.LEFT: total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight(); canvas.translate(ratio * (view.getWidth() - total) / 2, 0); break; case Gravity.BOTTOM: ratio = -1; case Gravity.TOP: Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics(); total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom(); canvas.translate(0, ratio * (view.getHeight() - total) / 2); break; } }
From source file:Main.java
public static void setUnderLine(TextView tv) { if (tv.getText() != null) { String udata = tv.getText().toString(); SpannableString content = new SpannableString(udata); content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); tv.setText(content);//from ww w . j a v a2 s .c om content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); } else { tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); } }
From source file:org.smssecure.smssecure.util.ViewUtil.java
public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) { if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) { return text; } else {/*from w w w . j a va2s. c o m*/ return TextUtils.ellipsize(text, view.getPaint(), view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(), TruncateAt.END); } }
From source file:Main.java
public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor, int messageTextSize, CharSequence title, CharSequence message) { titleTv.setMinHeight(titleTextSize * 3); if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) { titleTv.setTextColor(titleColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize); titleTv.getPaint().setFakeBoldText(true); titleTv.setText(title);/*from w w w . j a va2s .com*/ } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { titleTv.setTextColor(messageColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize); titleTv.setText(message); } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { SpannableString titleSs = new SpannableString(title + "\n" + message); titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleTv.setText(titleSs); titleTv.setLineSpacing(0.0f, 1.2f); } else { titleTv.setVisibility(View.GONE); } }
From source file:com.android.mail.browse.ConversationItemViewCoordinates.java
/** * Returns a negative corrective value that you can apply to a TextView's vertical dimensions * that will nudge the first line of text upwards such that uppercase Latin characters are * truly top-aligned.// w w w .j a va 2s. c o m * <p> * N.B. this will cause other characters to draw above the top! only use this if you have * adequate top margin. * */ private static int getLatinTopAdjustment(TextView t) { final FontMetricsInt fmi = t.getPaint().getFontMetricsInt(); return (fmi.top - fmi.ascent); }
From source file:Main.java
public static String getEllipsisedText(TextView textView) { try {// w ww .j ava 2 s . c o m String text = textView.getText().toString(); int lines = textView.getLineCount(); int width = textView.getWidth(); int len = text.length(); Log.d("Test", "text-->" + text + "; lines-->" + lines + "; width-->" + width + ";len-->" + len); TextUtils.TruncateAt where = TextUtils.TruncateAt.END; TextPaint paint = textView.getPaint(); StringBuffer result = new StringBuffer(); int spos = 0, cnt, tmp, hasLines = 0; while (hasLines < lines - 1) { cnt = paint.breakText(text, spos, len, true, width, null); if (cnt >= len - spos) { result.append(text.substring(spos)); break; } tmp = text.lastIndexOf('\n', spos + cnt - 1); if (tmp >= 0 && tmp < spos + cnt) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { tmp = text.lastIndexOf(' ', spos + cnt - 1); if (tmp >= spos) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { result.append(text.substring(spos, cnt)); spos += cnt; } } hasLines++; } if (spos < len) { result.append(TextUtils.ellipsize(text.subSequence(spos, len), paint, (float) width, where)); } return result.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }