Determining If a Style Attribute Applies to a Character or the Paragraph

All style attributes as defined in StyleConstants are either character- or paragraph-based attributes. See also Listing the Attributes in a Style.
boolean b; // Check if character-based attribute b = StyleConstants.Italic instanceof AttributeSet.CharacterAttribute; // true b = StyleConstants.LineSpacing instanceof AttributeSet.CharacterAttribute; // false // Check if paragraph-based attribute b = StyleConstants.LineSpacing instanceof AttributeSet.ParagraphAttribute; // true b = StyleConstants.Italic instanceof AttributeSet.ParagraphAttribute; // false
It is also possible to determine if the attribute is a color or a font-related attribute.
// Check if color-based attribute b = StyleConstants.Foreground instanceof AttributeSet.ColorAttribute; // true b = StyleConstants.Italic instanceof AttributeSet.ColorAttribute; // false // Check if font-based attribute b = StyleConstants.Italic instanceof AttributeSet.FontAttribute; // true b = StyleConstants.Foreground instanceof AttributeSet.FontAttribute; // false

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.