Class TTextView

All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent

public class TTextView extends ScrollView
A scrollable, multiline text region.
  • Constructor Details

    • TTextView

      public TTextView(Context context)
    • TTextView

      public TTextView(Context context, AttributeSet attrs)
    • TTextView

      public TTextView(Context context, AttributeSet attrs, int defStyleAttr)
    • TTextView

      @RequiresApi(api=21) public TTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
  • Method Details

    • onSizeChanged

      protected void onSizeChanged(int w, int h, int oldw, int oldh)
      Overrides:
      onSizeChanged in class ScrollView
    • onScrollChanged

      protected void onScrollChanged(int l, int t, int oldl, int oldt)
      Overrides:
      onScrollChanged in class View
    • hitTestPosition

      public int hitTestPosition(float x, float y)
      Performs hit testing. Returns the index of character representing the specified position, or -1 if there is no character at this position.
      Parameters:
      x - The x- coordinate of position.
      y - The y- coordinate of position.
      Returns:
      The index of character representing the specified position, or -1 if there is no character at this position.
    • setGravity

      public void setGravity(int gravity)
      Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the Label beyond what is required for the text itself.
      Parameters:
      gravity - The horizontal and vertical alignment.
    • getComposedFrame

      public ComposedFrame getComposedFrame()
      Returns the current composed frame that is being displayed.
      Returns:
      The composed frame being displayed.
    • getTypesetter

      public Typesetter getTypesetter()
      Returns the typesetter that is being used to compose text lines.
      Returns:
      The current typesetter.
    • setTypesetter

      public void setTypesetter(Typesetter typesetter)
      Sets the typesetter that should be used to compose text lines. Calling this method will make text and spanned properties null.

      A typesetter is preferred over spanned as it avoids an extra step of creating typesetter from spanned.

      Parameters:
      typesetter - A typesetter object.
      See Also:
    • getSpanned

      public Spanned getSpanned()
      Returns the current spanned that is being displayed. This property will be null if either text or typesetter is being used instead.
      Returns:
      The spanned being displayed.
      See Also:
    • setSpanned

      public void setSpanned(Spanned spanned)
      Sets the spanned that should be displayed. Calling this method will make text property null.

      If performance is required, a typesetter should be used directly.

      Parameters:
      spanned - The spanned to display.
      See Also:
    • getTypeface

      public Typeface getTypeface()
      Returns the current typeface in which the text is being displayed.
      Returns:
      The typeface being used for displaying text.
    • setTypeface

      public void setTypeface(Typeface typeface)
      Sets the typeface in which the text should be displayed.
      Parameters:
      typeface - The typeface to use for displaying text.
    • getText

      public String getText()
      Returns the current text that is being displayed. This property will be null if either spanned or typesetter is being used instead.
      Returns:
      The text being displayed.
      See Also:
    • setText

      public void setText(String text)
      Sets the text that should be displayed. Calling this method will make spanned property null.
      Parameters:
      text - The text to display.
      See Also:
    • getTextSize

      public float getTextSize()
      Returns the current text size (in pixels) in which the text is being displayed.
      Returns:
      The text size to use for displaying text.
    • setTextSize

      public void setTextSize(float textSize)
      Set the text size (in pixels) in which the text should be displayed.
      Parameters:
      textSize - The text size to use for displaying text.
    • getTextColor

      @ColorInt public int getTextColor()
      Returns the current color in which the text is being displayed.
      Returns:
      The color being used for displaying text.
    • setTextColor

      public void setTextColor(@ColorInt int textColor)
      Sets the color in which the text should be displayed.
      Parameters:
      textColor - The color to use for displaying text.
    • getExtraLineSpacing

      public float getExtraLineSpacing()
      Returns the extra spacing that should be added after each text line. It is resolved before line height multiplier. The default value is zero.
      Returns:
      The current extra line spacing.
      See Also:
    • setExtraLineSpacing

      public void setExtraLineSpacing(float extraLineSpacing)
      Sets the extra spacing that should be added after each text line. It is resolved before line height multiplier. The default value is zero.
      Parameters:
      extraLineSpacing - The extra line spacing in pixels.
      See Also:
    • getLineHeightMultiplier

      public float getLineHeightMultiplier()
      Returns the height multiplier that should be applied on each text line. It is resolved after extra line spacing. The default value is one.
      Returns:
      The current line height multiplier.
      See Also:
    • setLineHeightMultiplier

      public void setLineHeightMultiplier(float lineHeightMultiplier)
      Sets the height multiplier to apply on each text line. It is resolved after extra line spacing. The default value is one.

      The additional spacing is adjusted in such a way that text remains in the middle of the line.

      Parameters:
      lineHeightMultiplier - The multiplication factor.
      See Also:
    • isJustificationEnabled

      public boolean isJustificationEnabled()
      Returns whether or not to justify the text lines. The default value is false.
    • setJustificationEnabled

      public void setJustificationEnabled(boolean justificationEnabled)
      Sets whether or not to justify the text lines. The default value is false.
      Parameters:
      justificationEnabled - A boolean value specifying the justification enabled state.
    • getJustificationLevel

      @FloatRange(from=0.0, to=1.0) public float getJustificationLevel()
      Returns the justification level which can range from 0.0 to 1.0. A lower value increases the tightness between words while a higher value decreases it. The default value is 1.0f.
      Returns:
      The current justification level.
    • setJustificationLevel

      public void setJustificationLevel(@FloatRange(from=0.0,to=1.0) float justificationLevel)
      Sets the justification level which can range from 0.0 to 1.0. A lower value increases the tightness between words while a higher value decreases it. The default value is 1.0f.
      Parameters:
      justificationLevel - Justification level.
    • getSeparatorColor

      @ColorInt public int getSeparatorColor()
      Returns the color being used to display a separator line below each rendered text line. The default value is Color.TRANSPARENT.
      Returns:
      The current separator color.
    • setSeparatorColor

      public void setSeparatorColor(@ColorInt int separatorColor)
      Sets the color to display a separator line below each rendered text line. The default value is Color.TRANSPARENT.
      Parameters:
      separatorColor - The separator color.