Appendable, CharSequencepublic final class RichText extends Object implements Appendable, CharSequence
This class is the combination of Text and RichStyle. You can use
setRichStyle(ohos.agp.text.richstyles.RichStyle, int, int, ohos.agp.text.richstyles.RangedRichStyle.Flag) to add a rich style for the text.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
RichText.TouchEventListener |
已过时。
This change is effective since API version 8.
Replaced by
ClickRichStyle. |
| 构造器 | 说明 |
|---|---|
RichText() |
A constructor used to create a
RichText instance. |
RichText(String text) |
A constructor used to create a
RichText instance based on the specified text. |
RichText(RichText richText) |
A constructor used to create a
RichText instance based on the specified richText. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
addTouchEventListener(RichText.TouchEventListener listener,
int start,
int end) |
已过时。
This change is effective since API version 8.
Replaced by
ClickRichStyle. |
Appendable |
append(char c) |
Appends a character to the end of this rich text.
|
Appendable |
append(CharSequence charSequence) |
Appends the specified
charSequence to the end of this rich text. |
Appendable |
append(CharSequence charSequence,
int start,
int end) |
Appends the content in the range specified by
start and end of charSequence
to the end of this rich text. |
char |
charAt(int position) |
Obtains the character at the specified position in this rich text.
|
void |
delete(int start,
int end) |
Deletes the text and rich style in the range specified by
start and end from this rich text. |
void |
deleteAll() |
Deletes the text and all rich styles from this rich text.
|
void |
deleteRichStyles() |
Deletes all the rich styles from this rich text.
|
List<Integer> |
findAllTransitionPointsByCapability(int start,
int end,
int capability) |
Obtains all the transition points of a rich style in the range specified by
start and end
based on the capability. |
List<Integer> |
findAllTransitionPointsByTypeId(int start,
int end,
RichStyle.TypeId typeId) |
Obtains all the transition points of a rich style in the range specified by
start and end
based on the typeId. |
int |
findNextTransitionPointByCapability(int start,
int end,
int capability) |
Obtains the next transition point of a rich style in the range specified by
start and end
based on the capability. |
int |
findNextTransitionPointByTypeId(int start,
int end,
RichStyle.TypeId typeId) |
Obtains the next transition point of a rich style in the range specified by
start and end
based on the typeId. |
int |
getLeadingMargin(boolean firstMargin) |
已过时。
This change is effective since API version 8.
Replaced by
IndentRichStyle. |
RangedRichStyle |
getRangedRichStyle(RichStyle richStyle) |
Obtains the coverage and inclusion relationship of the specified rich style in this rich text.
|
List<RangedRichStyle> |
getRangedRichStylesByCapability(int start,
int end,
int capability) |
Obtains the list of rich styles corresponding to the
capability in the given range of this rich text. |
List<RangedRichStyle> |
getRangedRichStylesByTypeId(int start,
int end,
RichStyle.TypeId typeId) |
Obtains the list of rich styles of the specified
typeId in a given range of this rich text. |
void |
insert(int position,
String text) |
Inserts the specified text into the
position of this rich text. |
void |
insert(int position,
String text,
int textStart,
int textEnd) |
Inserts the content in the range specified by
textStart and textEnd in the text into
the position of this rich text. |
void |
insert(int position,
RichText richText) |
Inserts the specified rich text into the
position of this rich text. |
void |
insert(int position,
RichText richText,
int textStart,
int textEnd) |
Inserts the content in the range specified by
textStart and textEnd in the richText into
the position of this rich text. |
int |
length() |
Obtains the length of the string in this rich text.
|
void |
removeRichStyle(RichStyle richStyle) |
Removes the specified rich style from this rich text.
|
void |
removeRichStyleByCapability(int capability) |
Removes the rich style of the specified
capability from this rich text. |
void |
removeRichStyleByTypeId(RichStyle.TypeId typeId) |
Removes the rich styles enumerated by the
typeId from this rich text. |
void |
replace(int start,
int end,
String text) |
Replaces the content in the range specified by
start and end of this rich text
with the text. |
void |
replace(int start,
int end,
String text,
int textStart,
int textEnd) |
Replaces the content in the range specified by
start and end of this rich text with the
content in the range specified by textStart and textEnd in the text. |
void |
replace(int start,
int end,
RichText richText) |
Replaces the content in the range specified by
start and end of this rich text with
the richText. |
void |
replace(int start,
int end,
RichText richText,
int textStart,
int textEnd) |
Replaces the content in the range specified by
start and end of this rich text with the content
in the range specified by textStart and textEnd in the richText. |
void |
setLeadingMargin(int firstMargin,
int restMargin) |
已过时。
This change is effective since API version 8.
Replaced by
IndentRichStyle. |
void |
setRichStyle(RangedRichStyle rangedRichStyle) |
Sets a
RangedRichStyle for this rich text. |
void |
setRichStyle(RichStyle richStyle,
int start,
int end,
RangedRichStyle.Flag includeFlag) |
Sets a
RichStyle for this rich text. |
CharSequence |
subSequence(int start,
int end) |
Obtains a substring from this rich text.
|
String |
toString() |
Obtains the plain text from this rich text.
|
chars, codePointspublic RichText()
RichText instance. You can use setRichStyle(ohos.agp.text.richstyles.RichStyle, int, int, ohos.agp.text.richstyles.RangedRichStyle.Flag)
to add a rich style later.public RichText(String text)
RichText instance based on the specified text.
You can use setRichStyle(ohos.agp.text.richstyles.RichStyle, int, int, ohos.agp.text.richstyles.RangedRichStyle.Flag) to add a rich style later.text - Indicates the plain text, which can be null.public RichText(RichText richText)
RichText instance based on the specified richText.richText - Indicates the rich text, which cannot be null.IllegalArgumentException - Throws this exception if the specified richText is null.public char charAt(int position)
charAt 在接口中 CharSequenceposition - Indicates the position at which the character is to be obtained. The value must be greater
than or equal to 0 and less than the text length.IllegalArgumentException - Throws this exception if the value of position exceeds the text
length or is negative.public int length()
length 在接口中 CharSequencepublic CharSequence subSequence(int start, int end)
subSequence 在接口中 CharSequencestart - Indicates the start position in the rich text.end - Indicates the end position in the rich text.public String toString()
toString 在接口中 CharSequencetoString 在类中 Objectpublic Appendable append(CharSequence charSequence)
charSequence to the end of this rich text.append 在接口中 AppendablecharSequence - Indicates the rich text or plain text to append.public Appendable append(CharSequence charSequence, int start, int end)
start and end of charSequence
to the end of this rich text.append 在接口中 AppendablecharSequence - Indicates the rich text or plain text to append.start - Indicates the start position in the rich text or plain text.end - Indicates the end position in the rich text or plain text.public Appendable append(char c)
append 在接口中 Appendablec - Indicates the character to append.@Deprecated public void addTouchEventListener(RichText.TouchEventListener listener, int start, int end)
ClickRichStyle.listener - Indicates the touch event listener to add.start - Indicates the start position of the rich text paragraph that responds to a touch event.end - Indicates the end position of the rich text paragraph that responds to a touch event.@Deprecated public void setLeadingMargin(int firstMargin, int restMargin)
IndentRichStyle.firstMargin - Indicates the margin of the first line in the paragraph, in pixels.restMargin - Indicates the margin of the other lines in the paragraph, in pixels.@Deprecated public int getLeadingMargin(boolean firstMargin)
IndentRichStyle.firstMargin - Specifies whether to obtain the leading margin of the first line or the other lines
of this rich text paragraph. The value true means to obtain the margin of the first line,
and false means to obtain the margin of the other lines.public List<RangedRichStyle> getRangedRichStylesByTypeId(int start, int end, RichStyle.TypeId typeId)
typeId in a given range of this rich text.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.typeId - Indicates a RichStyle.TypeId object.RangedRichStyle objects, each of which includes a rich style, its coverage,
and its inclusion relationship if obtained; returns the List that contains zero elements if
no data is found.public List<RangedRichStyle> getRangedRichStylesByCapability(int start, int end, int capability)
capability in the given range of this rich text.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.capability - Indicates the capability of a rich style, which affects the character appearance and
paragraph presentation. For details, see RichStyle.Capability.RangedRichStyle objects, each of which includes a rich style, its coverage,
and its inclusion relationship if obtained; returns the List that contains zero elements if no
data is found.public RangedRichStyle getRangedRichStyle(RichStyle richStyle)
richStyle - Indicates the style of the rich text.RangedRichStyle object, which includes a rich style, its coverage, and its inclusion
relationship if obtained; returns null if no data is found.public void setRichStyle(RichStyle richStyle, int start, int end, RangedRichStyle.Flag includeFlag)
RichStyle for this rich text.
You must specify a richStyle, its start and end positions (start and end) in the
string, and the inclusion relationship (includeFlag) for adding text to the left and right boundaries.
Note: An exception is thrown if the range specified by start and end is incorrect. If a rich
style is set for multiple times, only the last setting is retained.
richStyle - Indicates the rich style to set.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.includeFlag - Indicates the inclusion relationship. For details, see RangedRichStyle.Flag.IllegalArgumentException - Throws this exception if the value of richStyle is null,
exceeds the text length, or is negative.public void setRichStyle(RangedRichStyle rangedRichStyle)
RangedRichStyle for this rich text.
rangedRichStyle specifies the rich style, start position, end position,
and inclusion relationship for adding text to the left and right boundaries.
Note: If a rich style is set for multiple times, only the last setting is retained.
rangedRichStyle - Indicates the RichStyle data structure stored in the rich text, which contains
the start position, end position, and inclusion relationship.IllegalArgumentException - Throws this exception if the value of rangedRichStyle is null,
exceeds the text length, or is negative.public int findNextTransitionPointByTypeId(int start,
int end,
RichStyle.TypeId typeId)
start and end
based on the typeId.start - Indicates the start position in the rich text. start is not included.end - Indicates the end position in the rich text. end is included.typeId - Indicates a RichStyle.TypeId object.end if no data is found.public int findNextTransitionPointByCapability(int start,
int end,
int capability)
start and end
based on the capability.start - Indicates the start position in the rich text. start is not included.end - Indicates the end position in the rich text. end is included.capability - Indicates the capability of a rich style, which affects the character appearance and
paragraph presentation. For details, see RichStyle.Capability.end if no data is found.public List<Integer> findAllTransitionPointsByTypeId(int start, int end, RichStyle.TypeId typeId)
start and end
based on the typeId.start - Indicates the start position in the rich text. start is not included.end - Indicates the end position in the rich text. end is included.typeId - Indicates a RichStyle.TypeId object.public List<Integer> findAllTransitionPointsByCapability(int start, int end, int capability)
start and end
based on the capability.start - Indicates the start position in the rich text. start is not included.end - Indicates the end position in the rich text. end is included.capability - Indicates the capability of a rich style, which affects the character appearance and
paragraph presentation. For details, see RichStyle.Capability.public void removeRichStyle(RichStyle richStyle)
richStyle is null, no rich style is removed.richStyle - Indicates the rich style to remove.public void removeRichStyleByTypeId(RichStyle.TypeId typeId)
typeId from this rich text.typeId - Indicates a RichStyle.TypeId object.public void removeRichStyleByCapability(int capability)
capability from this rich text.capability - Indicates the capability of a rich style, which affects the character appearance and
paragraph presentation. For details, see RichStyle.Capability.public void replace(int start,
int end,
String text)
start and end of this rich text
with the text.
Note:
null, the replacement
operation will not be performed.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.text - Indicates the text to be used for replacement.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void replace(int start,
int end,
RichText richText)
start and end of this rich text with
the richText.
Note:
null, the replacement
operation will not be performed.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.richText - Indicates the rich text to be used for replacement.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void replace(int start,
int end,
String text,
int textStart,
int textEnd)
start and end of this rich text with the
content in the range specified by textStart and textEnd in the text.
Note:
null, the replacement operation will not be performed.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.text - Indicates the text to be used for replacement.textStart - Indicates the start position in the text to be used for replacement.textEnd - Indicates the end position in the text to be used for replacement.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void replace(int start,
int end,
RichText richText,
int textStart,
int textEnd)
start and end of this rich text with the content
in the range specified by textStart and textEnd in the richText.
Note:
null, the replacement
operation will not be performed.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.richText - Indicates the rich text to be used for replacement.textStart - Indicates the start position in the rich text to be used for replacement.textEnd - Indicates the end position in the rich text to be used for replacement.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void deleteAll()
public void deleteRichStyles()
public void delete(int start,
int end)
start and end from this rich text.
No deletion is performed if the input parameters are invalid.start - Indicates the start position in the rich text.end - Indicates the end position in the rich text.public void insert(int position,
String text)
position of this rich text.
Note:
null, the insertion operation will not be
performed.position - Indicates the position where the text will be inserted.text - Indicates the text to insert.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void insert(int position,
RichText richText)
position of this rich text.
Note:
null, the insertion operation will not be
performed.position - Indicates the position where the rich text will be inserted.richText - Indicates the rich text to insert.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void insert(int position,
String text,
int textStart,
int textEnd)
textStart and textEnd in the text into
the position of this rich text.
Note:
null, the insertion operation will not be
performed.position - Indicates the position where the text will be inserted.text - Indicates the text to insert.textStart - Indicates the start position in the text to insert.textEnd - Indicates the end position in the text to insert.IllegalArgumentException - Throws this exception if an input parameter is invalid.public void insert(int position,
RichText richText,
int textStart,
int textEnd)
textStart and textEnd in the richText into
the position of this rich text.
Note:
null, the insertion operation will not be
performed.position - Indicates the position where the rich text will be inserted.richText - Indicates the rich text to insert.textStart - Indicates the start position in the rich text to insert.textEnd - Indicates the end position in the rich text to insert.IllegalArgumentException - Throws this exception if an input parameter is invalid.