I am placing text in a LabelField as multi-line. This is the method I am calling:
public void setFirstName(String fvalue,String lvalue,String date,String lastStatus)
{
_fnameLabel.setText(fvalue+" "+lvalue+"\n"+date+"\n"+lastStatus);
_fnameLabel.setFont((_fnameLabel.getFont().derive(Font.BOLD, 20, Ui.UNITS_px,
Font.ANTIALIAS_STANDARD, Font.COLORED_OUTLINE_EFFECT)));
_fnameLabel.setMargin(10, 0, 20, 0); //To leave some space from top and bottom
}
I want different font (size,style etc) for each line. Is it possible to have multi-format in one labelfield. Please help.
You can't do that with a
LabelField
, only with aRichTextField
. You have to build arrays of offsets, fonts, and font indices to use for the field. It's a bit tedious, but not particularly hard. The method you want to use iswhere:
offsets
is a sorted array of positions where formatting changes, including the start (0) and end (text.length()
) of the text;attributes
is an array of indexes into thefonts
array, one for each text region (offsets.length == attributes.length + 1
);fonts
is the array of different fonts you want to use.The
attributes
array can contain the same value more than once, sofonts.length
can be anything at all, as long as every element ofattributes
is a valid index of a non-null
element offonts
.