Example usage for android.widget TextView getPaint

List of usage examples for android.widget TextView getPaint

Introduction

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

Prototype

public TextPaint getPaint() 

Source Link

Document

Gets the TextPaint used for the text.

Usage

From source file:Main.java

public static void addUnderlineTextView(TextView tv) {
    tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
}

From source file:Main.java

public static void setHtmlLink(TextView tvTest) {
    tvTest.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    tvTest.getPaint().setAntiAlias(true);
}

From source file:Main.java

public static void setUnderlineStr(TextView tv, String str) {
    tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    tv.setText(str);//  ww  w. ja va2 s.c  o  m
}

From source file:Main.java

public static void setTVUnderLine(TextView textView) {
    textView.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    textView.getPaint().setAntiAlias(true);
}

From source file:Main.java

public static int getTextLen(TextView textView) {
    TextPaint paint = textView.getPaint();
    return (int) Layout.getDesiredWidth(textView.getText().toString(), 0, textView.getText().length(), paint);
}

From source file:Main.java

public static int fitLineCount(TextView view, String szText, int nWidth) {
    int nCharCount = view.getPaint().breakText(szText, 0, szText.length(), true, nWidth, null);
    int nLineCount = szText.length() / nCharCount;
    if (szText.length() > nCharCount * nLineCount)
        nLineCount++;/*from w w  w  .ja  v a 2s.c  o  m*/
    view.setLines(nLineCount);
    return nLineCount;
}

From source file:Main.java

public static int getLineCount(TextView view, String szText, int nWidth) {
    int nCharCount = view.getPaint().breakText(szText, 0, szText.length(), true, nWidth, null);
    int nLineCount = szText.length() / nCharCount;
    if (szText.length() > nCharCount * nLineCount)
        nLineCount++;//  ww  w . j  a v a2  s .  c  o m

    return nLineCount;
}

From source file:Main.java

/**
 * Method getTextWith() used to get the TextView's Content
 * //from w  w  w.j a  v a  2  s.co m
 * @param textView
 *            The processed TextView.
 * @param text
 *            The Content of TextView
 * @return
 */
public static int getTextWidth(TextView textView, String text) {
    Rect bounds = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(text, 0, text.length(), bounds);
    return bounds.width();
}

From source file:Main.java

public static int applyNewLineCharacter(TextView textView) {
    Paint paint = textView.getPaint();
    String text = (String) textView.getText();
    int frameWidth = getPixelFromDp(textView, 120f);
    int startIndex = 0;
    int endIndex = paint.breakText(text, true, frameWidth, null);
    String save = text.substring(startIndex, endIndex);
    // Count line of TextView
    int lines = 1;

    while (true) {
        // Set new start index
        startIndex = endIndex;/*from   w w w  .  j  a  va  2  s  . c  o m*/
        // Get substring the remaining of text
        text = text.substring(startIndex);

        if (text.length() == 0) {
            break;
        } else {
            lines++;
        }

        // Calculate end of index that fits
        endIndex = paint.breakText(text, true, frameWidth, null);
        // Append substring that fits into the frame
        save += "\n" + text.substring(0, endIndex);
    }
    // Set text to TextView
    textView.setText(save);

    return lines;
}

From source file:Main.java

public static int getTextViewMeasureWidth(TextView textView, String text) {
    if (textView == null)
        return 0;
    TextPaint paint = textView.getPaint();
    Rect rect = new Rect();
    paint.getTextBounds(text, 0, text.length(), rect);
    return Math.abs(rect.right - rect.left);
}