public class

TextLabel

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

Class Overview

A TextLabel represents a text into Screen.

This class displays a simple text label.

Default properties

By default, the following properties are applied to a new TextLabel:

  • not focusable (limited to some devices)
  • not clickable
  • enabled
  • no text
  • width content stretch : MATCH_PARENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : LEFT|TOP.

Cross Platform Considerations

  • On other platforms text ellipsis works by characters.
    e.g. "This text will be truncated" will become : "This text will be tru..."

Summary

XML Attributes
Attribute Name Related Method Description
contentAlignment setContentAlignment(int) A combination of alignment values (eg: TOP|LEFT)  
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
lines setLines(int) Number of lines  
marqueeEffect setMarqueeEffect(boolean) If the textlabel shows a horizontal scrolling text  
text setText(int) Res.string.XXXX or a text  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
underlineThickness setUnderlineThickness(int) eg: 10dp or 10 (dp is the default unit)  
[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
TextLabel()
Construct a label with no text
TextLabel(String text)
Constructs a label with the text given in parameter
TextLabel(int resId)
Constructs a label with the text given in parameter
Public Methods
int getContentAlignment()
Returns the current text alignment of the button
String getText()
Returns the current text of this label.
Color getTextColor()
Returns the current text color of this label
void setContentAlignment(int alignment)
Sets the alignment of the text in the button.
void setFont(Font font)
Sets the font of the label
void setLines(int lines)
Sets the number of lines of this text label.
void setMarqueeEffect(boolean marquee)
Enables or disables the "marquee" effect over this label.
void setMaxLines(int maxLines)
Makes the TextLabel at most this many lines tall.
void setText(String text)
Sets the text of the label
void setText(int resId)
Sets the text of the label
void setTextColor(Color color)
Sets the text color of this text label
void setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
void setUnderlineThickness(int thicknessInDP)
Sets the underline thickness of this label.
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

contentAlignment

A combination of alignment values (eg: TOP|LEFT)

Related Methods

font

Font resource id: Res.font.FONT_XXXX

Related Methods

lines

Number of lines

Related Methods

marqueeEffect

If the textlabel shows a horizontal scrolling text

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

underlineThickness

eg: 10dp or 10 (dp is the default unit)

Related Methods

Public Constructors

public TextLabel ()

Construct a label with no text

public TextLabel (String text)

Constructs a label with the text given in parameter

Parameters
text the new text

public TextLabel (int resId)

Constructs a label with the text given in parameter

Parameters
resId the string id representing the text of this text label

Public Methods

public int getContentAlignment ()

Returns the current text alignment of the button

Related XML Attributes
Returns
  • the integer combination of values from Alignment

public String getText ()

Returns the current text of this label. Returns an empty string ("") if there is no text.

Related XML Attributes
Returns
  • the current text. Returns an empty string ("") if there is no text.

public Color getTextColor ()

Returns the current text color of this label

Related XML Attributes
Returns
  • the current text color

public void setContentAlignment (int alignment)

Sets the alignment of the text in the button. The alignment will be used only if the text is smaller than the TextLabel size. (default : TOP|LEFT)

In MATCH_CONTENT mode, the TextLabel size is the same than the text size, then this alignment property will be inefficient.

The parameter is a combination of values from Alignment.

Related XML Attributes
Parameters
alignment The new alignment of the label's text
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setFont (Font font)

Sets the font of the label

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 setLines (int lines)

Sets the number of lines of this text label.

If the text is longer than this number of lines, the text will be truncated.

If the text is smaller than this number of lines, empty lines will be displayed after the text to reach the number of lines.

This method uses the setHeight() method, if a setHeight() have been use before it will be overwritten.

Related XML Attributes
Parameters
lines number of lines. If 0, no lines will be displayed. If -1, the number of lines displayed will rely on the text length and the stretch property of the TextLabel (default). If < -1, an exception will be raised.
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalArgumentException if lines is < -1

public void setMarqueeEffect (boolean marquee)

Enables or disables the "marquee" effect over this label.

The text will be displayed in a Single line mode. If the text is longer than this TextLabel bounds, then the text will scroll from left to right automatically.

If the text's width is lower than the label's width in marquee mode, then the marquee will be disabled because the user can see all the text.

Note: If the number of lines is modified or if the text contains return carriage, this mode will be disabled.

Related XML Attributes
Parameters
marquee true to enable the "marquee" effect

public void setMaxLines (int maxLines)

Makes the TextLabel at most this many lines tall.

Setting this value overrides any other (maximum) height setting.

Parameters
maxLines number of lines at most. If 0, no lines will be displayed. If -1, no limit of maximum lines will be set (default). If < -1, an exception will be raised.
Throws
CrossThreadException if the method is called from outside the UI-Thread
IllegalArgumentException if maxLines < -1

public void setText (String text)

Sets the text of the label

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

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 text label

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 sizeInDp)

Sets the text size to a given value (in dp).

Related XML Attributes
Parameters
sizeInDp size to set to the text

public void setUnderlineThickness (int thicknessInDP)

Sets the underline thickness of this label.

A negative or zero value means no underlined label.

Related XML Attributes
Parameters
thicknessInDP A negative or zero value means no underlined text, otherwise the parameter means the thickness of the line in DP units.
Throws
CrossThreadException if the method is called from outside the UI-Thread
See Also
  • Font#STYLE_UNDERLINED