public abstract class Attribute extends Boxed
Examples of setting up Attributes include:
attr = new StyleAttribute(Style.ITALIC);although many settings can be compounded by setting a FontDescription:
desc = new FontDescription("DejaVu Serif, 9pt"); attr = new FontDescriptionAttribute(desc);in general it's one Attribute per characteristic. You then aggregate these together in an AttributeList and then apply them to a Layout. See
AttributeListfor an example of using these on discrete parts of text.
When coding with Attributes be aware of the following restrictions:
The different text attribute manipulations you can do are analogous to those found on FontDescription and TextTag. Indeed, Pango's Attributes are the underlying mechanism powering TextView and Label's rendering of rich markup.
Pango Attributes have an internal ugliness which is that each one needs
to be told the offsets of text it applies to. The problem is that these are
in terms of UTF-8 bytes, which not something we have access to from Java
(nor would we want to expose such in our public API). We take care of
setting the start and end points properly when you call
setAttributes(), but you
have to have already set the text into the Layout for us to be able to do
|Modifier and Type||Method and Description|
Given the text already in a Pango Layout, a starting position, and a width, set the indexes of this Attribute accordingly.
public void setIndices(int offset, int width)
widthare in terms of Java characters. The result of this call is that the start_index and end_index properties of the specified Attribute will be set.
By default an Attribute added to an AttributeList covers all the text in whatever that AttributeList is applied to. If that's not what you want, you need to tell each Attribute what range it covers using this method.