public class

RichTextLabel

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.RichTextLabel

Class Overview

A RichTextLabel can display HTML strings.

To display plain text, use TextLabel.

Remarks about HTML parsing

Be aware that RichTextLabel is not a WebView: some complex tags and attributes may not be interpreted or ignored.
For example this is the case for style tag and attribute and font tag.

  • The <style> tag will be completely ignored and its content will not be displayed.
  • The <font> tag will be ignored but its content will be displayed.
The RichTextLabel will display its HTML text even if there are some HTML mistakes (missing ending tag, undefined tag, incomplete attribute...). However in this case the result may be slightly different between the platforms.

Hyperlink (<a> tag) can be set in a RichTextLabel. The corresponding text will be highlighted and the link can be clicked to open the page in the web browser.

Cross Platform Considerations

In Android platform, the text is truncated if it cannot entirely be displayed in the view (for example it may append in the case a setHeight(int) was done.

In iOS platform, before iOS 7.1, <a> tag links cannot be opened by tapping on them.

Summary

XML Attributes
Attribute Name Related Method Description
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
text setText(int) Res.string.XXXX or a text  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
RichTextLabel()
Builds a label with no text.
RichTextLabel(String label)
Builds a label with a given text.
RichTextLabel(int labelResId)
Builds a label with the text in the text resource file corresponding to an id.
Public Methods
void setFont(Font font)
Sets the font of the label.
void setText(String text)
Sets the text of the label.
void setText(int resId)
Sets the text of the label from the text resource file using an id.
void setTextColor(Color color)
Sets the text color of this label.
void setTextSize(int size)
Set the default text size to the given value.
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

font

Font resource id: Res.font.FONT_XXXX

Related Methods

text

Res.string.XXXX or a text

Related Methods

textColor

#AARRGGBB or a color

Related Methods

textSize

a size in dp

Related Methods

Public Constructors

public RichTextLabel ()

Builds a label with no text.

public RichTextLabel (String label)

Builds a label with a given text. This text can be an HTML string.

Parameters
label the new text

public RichTextLabel (int labelResId)

Builds a label with the text in the text resource file corresponding to an id. This text can be an HTML string.

Parameters
labelResId the string id representing the text of this label

Public Methods

public void setFont (Font font)

Sets the font of the label.

If the text is from an HTML string, the typeface and the style will be applied to all HTML tags. The size will be applied to the p tag. The other tags size will be scaled automatically according to the font size.

Related XML Attributes
Parameters
font the new font to set
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the font parameter is null

public void setText (String text)

Sets the text of the label. This text can be an HTML string.

Related XML Attributes
Parameters
text the new text
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setText (int resId)

Sets the text of the label from the text resource file using an id. This text can be an HTML string.

Related XML Attributes
Parameters
resId the string id representing the text of this text label
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextColor (Color color)

Sets the text color of this label.

If the color is also defined in the HTML code, the behavior of this method depends on the platform.

Related XML Attributes
Parameters
color The color to set (with the alpha channel)
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextSize (int size)

Set the default text size to the given value.

If the text is from an HTML string, it is the p tag that will take the given size. The other tags size will be scaled automatically according to the new size.

Related XML Attributes
Parameters
size the default text size
Throws
CrossThreadException if the method is called from outside the UI-Thread