鴻蒙OS Text

2022-10-08 14:53 更新

Text

java.lang.Object

|---ohos.agp.components.Component

|---|---ohos.agp.components.Text

public class Text
extends Component

顯示組件中的文本。

文本是基本的 UI 元素。

Since:

3

嵌套類摘要

修飾符和類型 描述
static class Text.ConversionType 枚舉轉(zhuǎn)換類型。
static interface Text.EditorActionListener 偵聽編輯器操作的更改事件。
static class Text.FontFamilyType 枚舉字體系列類型。
static interface Text.TextColorObserver 提供一個(gè)觀察者來監(jiān)聽組件中的文本顏色變化。
static interface Text.TextObserver 提供一個(gè)文本觀察器來觀察組件中的文本變化。
static interface Text.TextSizeObserver 提供一個(gè)觀察者來監(jiān)聽組件中文本大小的變化。
static class Text.TextSizeType 枚舉文本大小的類型。
static class Text.TruncationMode 指示如何截?cái)辔谋尽?/td>
從類 ohos.agp.components.Component 繼承的嵌套類/接口
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEvent

字段摘要

修飾符和類型 字段 描述
static int AUTO_CURSOR_POSITION 表示光標(biāo)所在的位置。
static int AUTO_SCROLLING_FOREVER 表示文本將始終處于自動(dòng)滾動(dòng)狀態(tài)。
從類 ohos.agp.components.Component 繼承的字段
ACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLE

構(gòu)造函數(shù)摘要

構(gòu)造函數(shù) 描述
Text(Context context) 默認(rèn)構(gòu)造函數(shù)用于使用默認(rèn)屬性集和樣式創(chuàng)建 Text 實(shí)例。
Text(Context context, AttrSet attrSet) 用于在 XML 文件解析后使用指定的屬性集和默認(rèn)樣式創(chuàng)建 Text 實(shí)例的構(gòu)造函數(shù)。
Text(Context context, AttrSet attrSet, String styleName) 用于在 XML 文件解析后使用指定的屬性集和指定的樣式創(chuàng)建 Text 實(shí)例的構(gòu)造函數(shù)。

方法總結(jié)

修飾符和類型 方法 描述
void addTextObserver(Text.TextObserver observer) 添加文本觀察器 TextObserver 以檢測(cè)文本是否更改。
boolean adjustCursorPosition() 檢查光標(biāo)是否可以移動(dòng)到可見位置。
void append(String text) 將文本字符串附加到文本組件中的現(xiàn)有文本。
void delete(int length) 刪除光標(biāo)前的文本。
void delete(int length, boolean back) 刪除光標(biāo)之前或之后的文本。
void delete(int length, boolean back, int pos) 從指定位置刪除文本。
float getAdditionalLineSpacing() 獲取添加到文本組件中每行高度的額外間距。
Element[] getAroundElements() 獲取文本周圍的元素對(duì)象。
int getAroundElementsPadding() 獲取文本和元素對(duì)象之間的填充。
Element[] getAroundElementsRelative() 獲取文本周圍的元素對(duì)象。
int[] getAutoFontSizeRule() 獲取自動(dòng)調(diào)整大小的規(guī)則。
int getAutoFontSizeStep() 獲取自動(dòng)調(diào)整大小的步驟。
int getAutoScrollingCount() 獲取文本的自動(dòng)滾動(dòng)次數(shù)。
long getAutoScrollingDuration() 獲取文本的自動(dòng)滾動(dòng)時(shí)長(zhǎng)。
int getBaseLine(int line) 獲取目標(biāo)線基線的 y 坐標(biāo)。
Element getBottomElement() 獲取文本底部的元素。
Element getBottonElement() 已棄用。 此更改從 API 版本 8 開始生效。由 getBottomElement() 替換。
void getBoundingRect(int line, Rect bounding) 獲取目標(biāo)線的邊界矩形。
Element getBubbleElement() 獲取光標(biāo)所在氣泡框的Element對(duì)象。
int getBubbleHeight() 獲取文本氣泡框的高度。
int getBubbleWidth() 獲取文本氣泡框的寬度。
int getCombinedPaddingBottom() 獲取此文本底部的組合填充。
int getCombinedPaddingEnd() 獲取文本末尾的組合填充。
int getCombinedPaddingLeft() 獲取此文本左側(cè)的組合填充。
int getCombinedPaddingRight() 獲取此文本右側(cè)的組合填充。
int getCombinedPaddingStart() 獲取此文本開頭的組合填充。
int getCombinedPaddingTop() 獲取此文本頂部的組合填充。
Element getCursorElement() 獲取文本中光標(biāo)的元素對(duì)象。
String getCustomInputMethodOptions() 獲取自定義輸入法選項(xiàng)。
String getEditableString() 獲取可編輯文本組件中的文本。
boolean getEditingText(EditingCapability request, EditingText text) 獲取可編輯的文本。
int getEditorAction() 獲取編輯器動(dòng)作。
CharSequence getEditorActionText() 獲取編輯器操作文本。
Element getEndElement() 獲取文本周圍的結(jié)束元素。
PacMap getExtraInputData(boolean isCreate) 獲取發(fā)送到輸入法的額外輸入數(shù)據(jù)。
int getFadeEffectBoundaryWidth() 獲取文本淡化效果區(qū)域的邊界寬度。
Font getFont() 獲取文本字體。
Text.FontFamilyType getFontFamilyType() 獲取此 Text 的字體系列類型。
String getFontFeatures() 獲取字體功能設(shè)置。
String getFontVariations() 獲取字體變化設(shè)置。
String getHint() 獲取文本為空時(shí)顯示的提示文本。
Color getHintColor() 獲取文本組件中提示文本的顏色。
TextLayout.HyphenationStrategy getHyphenationStrategy() 獲取該文本的自動(dòng)斷字策略。
InputFilter[] getInputFilters() 獲取輸入過濾器列表。
LocaleProfile getInputMethodLocales() 獲取此文本的建議 LocaleProfile。
int getInputMethodOption() 獲取文本的輸入法選項(xiàng)。
TextLayout.JustifyStrategy getJustifyStrategy() 獲取文本對(duì)齊策略。
Element getLeftElement() 獲取文本左側(cè)的元素。
float getLetterSpacing() 獲取文本字母之間的間距。
TextLayout.LineBreakStrategy getLineBreakStrategy() 獲取該文本的換行策略。
int getLineCount() 獲取此文本中的行數(shù)。
int getLineHeight() 獲取此文本中的行間高度。
LocaleProfile getLocales() 獲取此文本中的默認(rèn) LocaleProfile。
int getMaxAutoFontSize() 獲取自動(dòng)調(diào)整大小允許的最大文本大小。
int getMaxTextHeight() 獲取文本的最大高度。
int getMaxTextLines() 獲取文本組件中允許的最大行數(shù)。
int getMaxTextWidth() 獲取文本的最大寬度。
int getMaxWidthInEms() 獲取此文本的最大寬度,以 em 為單位。
int getMinAutoFontSize() 獲取自動(dòng)調(diào)整大小所允許的最小文本大小。
int getMinTextHeight() 獲取此 Text 的最小高度。
int getMinTextLines() 獲取此文本中的最小行數(shù)。
int getMinTextWidth() 獲取此 Text 的最小寬度。
int getMinWidthInEms() 獲取此文本的最小寬度,以 em 為單位。
float getNumOfFontHeight() 獲取行距乘數(shù),它在文本組件中的行之間提供額外的間距。
int getOffsetByCoordinates(float x, float y) 獲取距離指定位置最近的字符偏移量。
boolean getPaddingForText() 檢查文本是否有額外的填充空間。
Locale getPrimaryLocale() 獲取此文本的默認(rèn)語言環(huán)境。
RichText getRichText() 獲取文本組件中顯示的富文本。
Element getRightElement() 獲取文本右側(cè)的元素。
Color getSelectionColor() 獲取選定文本的顏色。
int getSelectionEnd() 獲得選擇邊的結(jié)束。
Element getSelectionLeftBubbleElement() 獲取顯示在選中氣泡框左側(cè)內(nèi)邊距區(qū)域的 Element 對(duì)象。
int getSelectionLeftBubbleHeight() 獲取所選氣泡框左側(cè)填充區(qū)域的高度。
int getSelectionLeftBubbleWidth() 獲取所選氣泡框左側(cè)填充區(qū)域的寬度。
Element getSelectionRightBubbleElement() 獲取顯示在選中氣泡框右側(cè)內(nèi)邊距區(qū)域的 Element 對(duì)象。
int getSelectionRightBubbleHeight() 獲取所選氣泡框右側(cè)填充區(qū)域的高度。
int getSelectionRightBubbleWidth() 獲取所選氣泡框右側(cè)填充區(qū)域的寬度。
int getSelectionStart() 獲取選擇邊的起點(diǎn)。
Element getStartElement() 獲取文本周圍的起始元素。
String getText() 獲取文本組件中顯示的文本。
int getTextAlignment() 獲取文本組件中的文本對(duì)齊方式。
Color getTextColor() 獲取文本組件的文本顏色。
Text.ConversionType getTextConversion() 獲取此文本的 ConversionType。
BidiAnalyzer.BidiStrategy getTextDirectionStrategy() 獲取文本方向策略。
float getTextHorizontalScale() 獲取此 Text 的水平乘數(shù)。
int getTextInputType() 獲取Text的文本輸入類型。
Color getTextShadowColor() 獲取文本陰影的顏色。
float getTextShadowOffsetX() 獲取文本陰影的水平偏移量。
float getTextShadowOffsetY() 獲取文本陰影的垂直偏移量。
float getTextShadowRadius() 獲取文本陰影的模糊半徑。
int getTextSize() 獲取文本組件的文本大小。
int getTextSize(Text.TextSizeType textSizeType) 獲取文本的字體大小。
int getTextToBottomSpace() 獲取顯示的文本底部到文本組件底部的距離。
int getTextToTopSpace() 獲取顯示的文本頂部到文本組件頂部的距離。
Element getTopElement() 獲取文本頂部的元素。
Text.TruncationMode getTruncationMode() 獲取截?cái)嗄J健?/td>
ListUrlRichStyle getUrls() 獲取此文本中的超鏈接列表。
void insert(String text) 在光標(biāo)所在位置插入文本。
void insert(String text, int pos) 在指定位置插入文本。
boolean isAdjustInputPanel() 獲取在彈出輸入法面板時(shí)是否開啟自動(dòng)文本組件重新布局。
boolean isAllUpperCase() 檢查應(yīng)用于此文本的 ConversionType 是否設(shè)置為 ConversionType#ALL_UPPERCASE。
boolean isAutoFontSize() 獲取是否自動(dòng)調(diào)整文本大小以填充在組件內(nèi)。
boolean isAutoSelectEnabled() 獲取文本獲得焦點(diǎn)時(shí)是否選擇所有文本。
boolean isEditable() 檢查此文本是否可編輯。
boolean isFallbackFontMetricsEnabled() 檢查是否為后備字體啟用了上升或下降指標(biāo)。
boolean isFocusedByTouch() 當(dāng)你觸摸它時(shí)檢查這個(gè)文本是否有焦點(diǎn)。
boolean isHyperLinkClickable() 檢查此文本中的超鏈接是否可單擊。
boolean isInputMethodActive() 檢查此 Text 是否是當(dāng)前輸入法的目標(biāo)。
boolean isMultipleLine() 獲取文本是否在文本組件中多行顯示。
boolean isScrollable() 獲取文本在文本組件中是否可滾動(dòng)。
boolean isSoftInputVisibleOnFocus() 檢查當(dāng)此文本獲得焦點(diǎn)時(shí)軟輸入是否可見。
boolean isTextCursorVisible() 獲取光標(biāo)對(duì)于可編輯文本組件是否可見。
boolean isTextSelectable() 檢查是否可以選擇此文本。
int length() 獲取文本組件中允許的文本長(zhǎng)度。
void lockEditingState() 鎖定輸入法并開始文本編輯。
boolean moveToPosition(int offset) 根據(jù)指定的偏移量將字符移動(dòng)到可見位置。
boolean onCustomInputMethodCommand(String action, PacMap data) 由框架調(diào)用以響應(yīng)來自輸入法的自定義命令。
void onLockEditingState() 當(dāng)輸入法被鎖定時(shí)調(diào)用。
protected void onRtlChanged(Component.LayoutDirection layoutDirection) 在更改任何 RTL 屬性時(shí)調(diào)用。
boolean onTextEditorAction(int actionCode) 在處理指定編輯器操作的更改事件時(shí)調(diào)用。
void onUnlockEditingState() 當(dāng)輸入法解鎖時(shí)調(diào)用。
void removeTextObserver(Text.TextObserver observer) 刪除文本觀察者 TextObserver。
void setAdjustInputPanel(boolean adjust) 設(shè)置當(dāng)軟輸入面板彈出或隱藏時(shí)布局是否應(yīng)調(diào)整大小。
void setAroundElements(Element left, Element top, Element right, Element bottom) 圍繞文本設(shè)置元素對(duì)象。
void setAroundElementsPadding(int padding) 設(shè)置文本和元素對(duì)象之間的填充。
void setAroundElementsRelative(Element start, Element top, Element end, Element bottom) 圍繞文本設(shè)置元素對(duì)象。
void setAutoCursorAdjustmentEnabled(boolean isAutoMove) 將光標(biāo)設(shè)置為自動(dòng)移動(dòng)。
void setAutoFontSize(boolean autoFontSize) 設(shè)置是否自動(dòng)調(diào)整文本大小以填充組件。
void setAutoFontSize(boolean autoFontSize, boolean userSizeFirst) 設(shè)置是否自動(dòng)調(diào)整字體大小以填充組件內(nèi),以及是否在啟用自動(dòng)字體大小適應(yīng)之前嘗試指定的字體大小。
void setAutoFontSizeRule(int[] preSet) 設(shè)置所有可能的自動(dòng)字體大小的數(shù)組。
void setAutoFontSizeRule(int minFontSize, int maxFontSize, int autoFontStep) 設(shè)置自動(dòng)字體大小的范圍和步長(zhǎng)。
void setAutoScrollingCount(int count) 設(shè)置文本的自動(dòng)滾動(dòng)計(jì)數(shù)。
void setAutoScrollingDuration(long duration) 設(shè)置長(zhǎng)文本的自動(dòng)滾動(dòng)持續(xù)時(shí)間。
void setAutoSelectEnabled(boolean isSelectAll) 設(shè)置 thisText 有焦點(diǎn)時(shí)是否選擇所有文本。
void setBubbleElement(int resId) 為光標(biāo)所在的氣泡設(shè)置一個(gè) Element 對(duì)象。
void setBubbleElement(Element element) 為光標(biāo)所在的氣泡設(shè)置一個(gè) Element 對(duì)象。
void setBubbleHeight(int height) 設(shè)置文本氣泡框的高度。
void setBubbleSize(int width, int height) 設(shè)置顯示文本的氣泡框的寬度和高度。
void setBubbleWidth(int width) 設(shè)置文本氣泡框的寬度。
void setCursorElement(int resId) 為文本中的光標(biāo)設(shè)置元素對(duì)象。
void setCursorElement(Element element) 設(shè)置此 Text 中光標(biāo)的 Element 對(duì)象。
boolean setCursorPosition(int position) 設(shè)置文本的光標(biāo)位置。
void setCustomInputMethodOptions(String options) 設(shè)置此文本的自定義輸入法選項(xiàng)。
void setEditable(boolean isEditable) 設(shè)置此文本的可編輯性。
void setEditorActionListener(Text.EditorActionListener listener) 為組件中的編輯器操作注冊(cè)一個(gè)偵聽器。
void setEditorActionText(CharSequence text, int action) 設(shè)置編輯器操作文本。
void setExtraInputData(PacMap data) 為此文本設(shè)置額外的輸入數(shù)據(jù)。
void setFadeEffectBoundaryWidth(int width) 設(shè)置文本的淡入淡出效果區(qū)域的邊界寬度。
void setFallbackFontMetricsEnabled(boolean isEnable) 設(shè)置是否為后備字體啟用上升或下降指標(biāo)。
void setFont(Font font) 設(shè)置文本字體。
void setFontFamilyType(Text.FontFamilyType type) 設(shè)置此文本的字體系列。
void setFontFeatures(String settings) 設(shè)置字體特征。
boolean setFontVariations(String variation) 設(shè)置 TrueType 或 OpenType 字體變體設(shè)置。
void setHint(int resId) 設(shè)置此 Text 為空時(shí)顯示的提示文本。
void setHint(String hint) 設(shè)置文本為空時(shí)顯示的提示文本。
void setHintColor(Color color) 設(shè)置文本組件中提示文本的顏色。
void setHyperLinkClickable(boolean isClickable) 設(shè)置此文本中超鏈接的可點(diǎn)擊性。
void setHyperLinkColor(Color color) 設(shè)置文本中鏈接的顏色。
void setHyphenationStrategy(TextLayout.HyphenationStrategy strategy) 設(shè)置此文本的自動(dòng)斷字策略。
void setInputFilters(InputFilter[] filters) 設(shè)置文本的輸入過濾器列表。
void setInputMethodLocales(LocaleProfile locales) 為此文本設(shè)置建議的 LocaleProfile。
void setInputMethodOption(int option) 設(shè)置文本的輸入法選項(xiàng)。
void setJustifyStrategy(TextLayout.JustifyStrategy strategy) 設(shè)置文本對(duì)齊策略。
void setLeftBubbleHeight(int height) 設(shè)置文本左側(cè)氣泡框的高度。
void setLeftBubbleSize(int width, int height) 設(shè)置顯示文本的氣泡框左側(cè)填充區(qū)域的寬度和高度。
void setLeftBubbleWidth(int width) 設(shè)置文本左側(cè)氣泡框的寬度。
void setLetterSpacing(float spacing) 設(shè)置文本字母之間的間距。
void setLineBreakStrategy(TextLayout.LineBreakStrategy strategy) 設(shè)置此文本的換行策略。
void setLineHeight(int lineHeight) 設(shè)置此文本的行之間的高度。
void setLines(int lines) 設(shè)置此文本的行數(shù)。
void setLineSpacing(float add, float mult) 設(shè)置文本組件的行距。
void setLocales(LocaleProfile locales) 設(shè)置用于繪制此文本的 LocaleProfile。
void setMaxCharacters(int maxValue) 設(shè)置此文本的最大字符數(shù)。
void setMaxTextHeight(int maxTextHeight) 設(shè)置文本的最大高度。
void setMaxTextLines(int maxLines) 設(shè)置文本組件中允許的最大行數(shù)。
void setMaxTextWidth(int maxTextWidth) 設(shè)置文本的最大寬度。
void setMaxWidthInEms(int maxEms) 設(shè)置此文本的最大寬度,以 em 為單位。
void setMinTextHeight(int minHeight) 設(shè)置此文本的最小高度。
void setMinTextLines(int minLines) 設(shè)置此文本的最小行數(shù)。
void setMinTextWidth(int minWidth) 設(shè)置此文本的最小寬度。
void setMinWidthInEms(int minEms) 設(shè)置此文本的最小寬度,以 em 為單位。
void setMultipleLine(boolean multiple) 設(shè)置文本是否在文本組件中多行顯示。
void setPaddingForText(boolean hasPadding) 設(shè)置文本是否有額外的填充空間。
void setPrimaryLocale(Locale locale) 設(shè)置用于繪制此文本的區(qū)域設(shè)置。
void setRichText(RichText richText) 設(shè)置要在文本組件中顯示的富文本。
void setRightBubbleHeight(int height) 設(shè)置文本右側(cè)氣泡框的高度。
void setRightBubbleSize(int width, int height) 設(shè)置顯示文本的氣泡框右側(cè)填充區(qū)域的寬度和高度。
void setRightBubbleWidth(int width) 設(shè)置文本右側(cè)氣泡框的寬度。
void setScrollable(boolean scrollable) 設(shè)置文本是否可滾動(dòng)。
boolean setSelection(int start, int end) 設(shè)置此文本的選擇范圍。
void setSelectionColor(Color color) 設(shè)置選定文本的顏色。
void setSelectionLeftBubbleElement(int resId) 設(shè)置要為左側(cè)氣泡顯示的元素對(duì)象。
void setSelectionLeftBubbleElement(Element element) 設(shè)置要為左側(cè)氣泡顯示的元素對(duì)象。
void setSelectionRightBubbleElement(int resId) 設(shè)置要為右側(cè)氣泡顯示的元素對(duì)象。
void setSelectionRightBubbleElement(Element element) 設(shè)置要為右側(cè)氣泡顯示的元素對(duì)象。
void setSoftInputVisibleOnFocus(boolean isShow) 設(shè)置當(dāng)此文本獲得焦點(diǎn)時(shí)是否使軟輸入可見。
void setText(int resId) 設(shè)置要顯示的文本的資源 ID。
void setText(String text) 設(shè)置要在文本組件中顯示的文本。
void setTextAlignment(int textAlignment) 設(shè)置文本組件中的文本對(duì)齊方式。
void setTextColor(Color color) 設(shè)置文本組件的文本顏色。
void setTextConversion(Text.ConversionType conversionType) 設(shè)置此文本的 ConversionType。
void setTextCursorVisible(boolean visible) 設(shè)置光標(biāo)對(duì)于可編輯文本組件是否可見。
void setTextDirectionStrategy(BidiAnalyzer.BidiStrategy strategy) 設(shè)置文本方向策略。
void setTextHeight(int pixels) 設(shè)置此文本的固定高度。
void setTextHorizontalScale(float ratio) 設(shè)置此文本的水平乘數(shù)。
void setTextInputType(int inputType) 設(shè)置 Text 的文本輸入類型。
void setTextSelectable(boolean isSelectable) 設(shè)置此文本是否可選。
void setTextShadow(float offsetX, float offsetY, float radius, Color color) 設(shè)置此文本的陰影。
void setTextSize(int size) 為文本設(shè)置指定的字體大小。
void setTextSize(int size, Text.TextSizeType textSizeType) 為具有指定文本大小類型的文本組件設(shè)置文本大小。
void setTextWidth(int width) 設(shè)置此文本的確切寬度。
void setTextWidthInEms(int ems) 設(shè)置此文本的寬度,以 em 為單位。
void setTruncationMode(Text.TruncationMode mode) 當(dāng)文本內(nèi)容長(zhǎng)于組件寬度時(shí)設(shè)置截?cái)嗄J健?/td>
void startAutoScrolling() 開始文本自動(dòng)滾動(dòng)。
void stopAutoScrolling() 停止文本自動(dòng)滾動(dòng)。
void unlockEditingState() 解鎖輸入法并結(jié)束文本編輯。
從類 ohos.agp.components.Component 繼承的方法
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, dispatchRestoreState, dispatchSaveState, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findComponentById, findComponentHolderById, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, informConfigurationChanged, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onDrag, onRestoreState, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEvents
從類 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

字段詳細(xì)信息

AUTO_CURSOR_POSITION

public static final int AUTO_CURSOR_POSITION

表示光標(biāo)所在的位置。

AUTO_SCROLLING_FOREVER

public static final int AUTO_SCROLLING_FOREVER

表示文本將始終處于自動(dòng)滾動(dòng)狀態(tài)。

構(gòu)造函數(shù)詳細(xì)信息

Text

public Text(Context context)

默認(rèn)構(gòu)造函數(shù)用于使用默認(rèn)屬性集和樣式創(chuàng)建 Text 實(shí)例。

參數(shù):

參數(shù)名稱 參數(shù)描述
context 指示應(yīng)用程序上下文。

Text

public Text(Context context, AttrSet attrSet)

用于在 XML 文件解析后使用指定的屬性集和默認(rèn)樣式創(chuàng)建 Text 實(shí)例的構(gòu)造函數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
context 指示應(yīng)用程序上下文。
attrSet 指示要使用的屬性集。

Text

public Text(Context context, AttrSet attrSet, String styleName)

用于在 XML 文件解析后使用指定的屬性集和指定的樣式創(chuàng)建 Text 實(shí)例的構(gòu)造函數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
context 指示應(yīng)用程序上下文。
attrSet 指示要使用的屬性集。
styleName 指示要使用的樣式名稱。

方法詳情

addTextObserver

public void addTextObserver(Text.TextObserver observer)

添加文本觀察器 TextObserver 以檢測(cè)文本是否更改。

在使用 TextObserver 之前,您必須實(shí)現(xiàn) TextObserver#onTextUpdated。

參數(shù):

參數(shù)名稱 參數(shù)描述
observer 指示要添加的文本觀察者。

removeTextObserver

public void removeTextObserver(Text.TextObserver observer)

刪除文本觀察者 TextObserver。

參數(shù):

參數(shù)名稱 參數(shù)描述
observer 指示要?jiǎng)h除的文本觀察者。

setEditorActionListener

public void setEditorActionListener(Text.EditorActionListener listener)

為組件中的編輯器操作注冊(cè)一個(gè)偵聽器。

參數(shù):

參數(shù)名稱 參數(shù)描述
listener 指示編輯器操作的偵聽器。

setFont

public void setFont(Font font)

設(shè)置文本字體。

參數(shù):

參數(shù)名稱 參數(shù)描述
font 表示文本字體。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果文本字體為空,則引發(fā)異常。

getFont

public Font getFont()

獲取文本字體。

返回:

返回文本字體。

setTruncationMode

public void setTruncationMode(Text.TruncationMode mode)

當(dāng)文本內(nèi)容長(zhǎng)于組件寬度時(shí)設(shè)置截?cái)嗄J健?/p>

當(dāng)文本組件不能在一行中顯示所有文本內(nèi)容時(shí),可以選擇以下模式:(1)文本的開頭、中間或結(jié)尾被截?cái)?,截?cái)嗖糠诛@示為省略號(hào),(2 ) 文本將滾動(dòng)顯示完整內(nèi)容或 (3) 直接截?cái)?,無需任何特殊處理。

參數(shù):

參數(shù)名稱 參數(shù)描述
mode 表示截?cái)嗄J健?/td>

getTruncationMode

public Text.TruncationMode getTruncationMode()

獲取截?cái)嗄J健?/p>

返回:

返回截?cái)嗄J剑?如果未設(shè)置模式,則返回 TruncationMode#NONE。

setInputMethodOption

public void setInputMethodOption(int option)

設(shè)置文本的輸入法選項(xiàng)。

參數(shù):

參數(shù)名稱 參數(shù)描述
option 表示文本的輸入法選項(xiàng)。

getInputMethodOption

public int getInputMethodOption()

獲取文本的輸入法選項(xiàng)。

返回:

返回文本的輸入法選項(xiàng)。

setAutoFontSizeRule

public void setAutoFontSizeRule(int minFontSize, int maxFontSize, int autoFontStep)

設(shè)置自動(dòng)字體大小的范圍和步長(zhǎng)。

最小字體大小必須小于最大字體大小,并且字體大小步長(zhǎng)必須大于 0。

參數(shù):

參數(shù)名稱 參數(shù)描述
minFontSize 指示最小自動(dòng)字體大小。
maxFontSize 指示最大自動(dòng)字體大小。
autoFontStep 指示自動(dòng)字體大小步長(zhǎng)。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果最小或最大字體大小值小于 0 或步長(zhǎng)小于 0,則引發(fā)異常。

setAutoFontSizeRule

public void setAutoFontSizeRule(int[] preSet)

設(shè)置所有可能的自動(dòng)字體大小的數(shù)組。

參數(shù):

參數(shù)名稱 參數(shù)描述
preSet 指示所有可能的自動(dòng)字體大小的數(shù)組。

getAutoFontSizeRule

public int[] getAutoFontSizeRule()

獲取自動(dòng)調(diào)整大小的規(guī)則。

返回:

返回規(guī)則。

Since:

7

isAutoFontSize

public boolean isAutoFontSize()

獲取是否自動(dòng)調(diào)整文本大小以填充在組件內(nèi)。

返回:

如果自動(dòng)調(diào)整文本大小以填充組件,則返回 true; 否則返回 false。

getMinAutoFontSize

public int getMinAutoFontSize()

獲取自動(dòng)調(diào)整大小所允許的最小文本大小。

返回:

如果獲得,則返回最小文本大小(以像素為單位); 如果未配置自動(dòng)調(diào)整大小,則返回 0。

Since:

7

getMaxAutoFontSize

public int getMaxAutoFontSize()

獲取自動(dòng)調(diào)整大小允許的最大文本大小。

返回:

如果獲得,則返回最大文本大?。ㄒ韵袼貫閱挝唬?; 如果未配置自動(dòng)調(diào)整大小,則返回 0。

Since:

7

getAutoFontSizeStep

public int getAutoFontSizeStep()

獲取自動(dòng)調(diào)整大小的步驟。

返回:

如果獲得,則返回步驟; 如果未配置自動(dòng)調(diào)整大小,則返回 0。

Since:

7

getTextHorizontalScale

public float getTextHorizontalScale()

獲取此 Text 的水平乘數(shù)。

默認(rèn)水平乘數(shù)為 1.0。

返回:

返回水平乘數(shù)。

Since:

7

setTextHorizontalScale

public void setTextHorizontalScale(float ratio)

設(shè)置此文本的水平乘數(shù)。

默認(rèn)水平乘數(shù)為 1.0。

參數(shù):

參數(shù)名稱 參數(shù)描述
ratio 指示要設(shè)置的水平乘數(shù)。

Since:

7

setTextWidth

public void setTextWidth(int width)

設(shè)置此文本的確切寬度。

設(shè)置此值會(huì)覆蓋之前的最小或最大寬度配置。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 指示要設(shè)置的確切寬度。

Since:

7

setMinTextWidth

public void setMinTextWidth(int minWidth)

設(shè)置此文本的最小寬度。

參數(shù):

參數(shù)名稱 參數(shù)描述
minWidth 指示要設(shè)置的最小寬度。

Since:

7

getMinTextWidth

public int getMinTextWidth()

獲取此 Text 的最小寬度。

返回:

返回此文本的最小寬度。

Since:

7

setAutoScrollingDuration

public void setAutoScrollingDuration(long duration)

設(shè)置長(zhǎng)文本的自動(dòng)滾動(dòng)持續(xù)時(shí)間。

在啟用自動(dòng)滾動(dòng)之前,您必須在文本上使用此方法。 自動(dòng)滾動(dòng)持續(xù)時(shí)間必須大于或等于 0,以毫秒為單位。 如果持續(xù)時(shí)間設(shè)置為 0,則使用默認(rèn)滾動(dòng)速度。

參數(shù):

參數(shù)名稱 參數(shù)描述
duration 指示文本組件的自動(dòng)滾動(dòng)持續(xù)時(shí)間。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于 0,則引發(fā)異常。

getAutoScrollingDuration

public long getAutoScrollingDuration()

獲取文本的自動(dòng)滾動(dòng)時(shí)長(zhǎng)。

返回:

如果可用,則返回為此文本設(shè)置的自動(dòng)滾動(dòng)持續(xù)時(shí)間; 否則返回 0。

setAutoScrollingCount

public void setAutoScrollingCount(int count)

設(shè)置文本的自動(dòng)滾動(dòng)計(jì)數(shù)。

在啟用自動(dòng)滾動(dòng)之前,您必須在文本上使用此方法。

參數(shù):

參數(shù)名稱 參數(shù)描述
count 表示文本的自動(dòng)滾動(dòng)次數(shù),必須大于等于1,或者AUTO_SCROLLING_FOREVER,表示文本組件永遠(yuǎn)處于自動(dòng)滾動(dòng)狀態(tài)。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值無效,則引發(fā)異常。

getAutoScrollingCount

public int getAutoScrollingCount()

獲取文本的自動(dòng)滾動(dòng)次數(shù)。

返回:

返回文本的自動(dòng)滾動(dòng)計(jì)數(shù)。

startAutoScrolling

public void startAutoScrolling()

開始文本自動(dòng)滾動(dòng)。

stopAutoScrolling

public void stopAutoScrolling()

停止文本自動(dòng)滾動(dòng)。

setCursorElement

public void setCursorElement(Element element)

設(shè)置此 Text 中光標(biāo)的 Element 對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
element 指示要設(shè)置的 Element 對(duì)象。

setCursorElement

public void setCursorElement(int resId)

為文本中的光標(biāo)設(shè)置元素對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 表示文本中光標(biāo)所在的 Element 資源 id。

Since:

7

setAutoCursorAdjustmentEnabled

public void setAutoCursorAdjustmentEnabled(boolean isAutoMove)

將光標(biāo)設(shè)置為自動(dòng)移動(dòng)。

參數(shù):

參數(shù)名稱 參數(shù)描述
isAutoMove 指定光標(biāo)滾動(dòng)到視線之外時(shí)是否會(huì)自動(dòng)移動(dòng)到可見位置。 值 true 表示光標(biāo)會(huì)自動(dòng)移動(dòng)到可見位置,false 表示相反。

Since:

7

getCursorElement

public Element getCursorElement()

獲取文本中光標(biāo)的元素對(duì)象。

返回:

返回文本中光標(biāo)的元素對(duì)象。

setAroundElements

public void setAroundElements(Element left, Element top, Element right, Element bottom)

圍繞文本設(shè)置元素對(duì)象。

此方法將元素對(duì)象放置在文本的左側(cè)、頂部、右側(cè)和底部。 元素對(duì)象的邊由文本的閱讀方式?jīng)Q定。

注意:如果未設(shè)置元素的邊界,則此方法將其設(shè)置為最佳尺寸。

參數(shù):

參數(shù)名稱 參數(shù)描述
left 指示文本左側(cè)的元素對(duì)象。
top 指示元素對(duì)象位于文本的頂部。
right 指示文本右側(cè)的元素對(duì)象。
bottom 指示文本底部的元素對(duì)象。

getAroundElements

public Element[] getAroundElements()

獲取文本周圍的元素對(duì)象。

文本左側(cè)、頂部、右側(cè)和底部的元素對(duì)象按順序返回。

返回:

返回文本周圍的元素對(duì)象。

getLeftElement

public Element getLeftElement()

獲取文本左側(cè)的元素。

元素是指圍繞文本的圖形材料。

返回:

返回左側(cè)元素。

Since:

4

getRightElement

public Element getRightElement()

獲取文本右側(cè)的元素。

元素是指圍繞文本的圖形材料。

返回:

返回正確的元素。

Since:

4

getTopElement

public Element getTopElement()

獲取文本頂部的元素。

元素是指圍繞文本的圖形材料。

返回:

返回頂部元素。

Since:

4

getBottonElement

@Deprecated public Element getBottonElement()

已棄用。 此更改從 API 版本 8 開始生效。由 getBottomElement() 替換。

獲取文本底部的元素。

元素是指圍繞文本的圖形材料。

返回:

返回底部元素。

Since:

4

getBottomElement

public Element getBottomElement()

獲取文本底部的元素。

元素是指圍繞文本的圖形材料。

返回:

返回底部元素。

Since:

7

getStartElement

public Element getStartElement()

獲取文本周圍的起始元素。

元素是指圍繞文本的圖形材料。

返回:

返回起始元素。

Since:

4

getEndElement

public Element getEndElement()

獲取文本周圍的結(jié)束元素。

元素是指圍繞文本的圖形材料。

返回:

返回結(jié)束元素。

Since:

4

setAroundElementsRelative

public void setAroundElementsRelative(Element start, Element top, Element end, Element bottom)

圍繞文本設(shè)置元素對(duì)象。

注意:如果未設(shè)置元素的邊界,則此方法將其設(shè)置為最佳尺寸。

參數(shù):

參數(shù)名稱 參數(shù)描述
start 指示文本開頭的元素對(duì)象,如果文本從左側(cè)開始,則在文本的左側(cè),反之亦然。
top 指示元素對(duì)象位于文本的頂部。
end 表示文本末尾的元素對(duì)象,如果文本從右開始,則在文本的左側(cè),反之亦然。
bottom 指示文本底部的元素對(duì)象。

getAroundElementsRelative

public Element[] getAroundElementsRelative()

獲取文本周圍的元素對(duì)象。

文本開頭、頂部、末尾和底部的元素對(duì)象按順序返回。

返回:

返回文本周圍的元素對(duì)象。

setAroundElementsPadding

public void setAroundElementsPadding(int padding)

設(shè)置文本和元素對(duì)象之間的填充。

參數(shù):

參數(shù)名稱 參數(shù)描述
padding 指示文本和元素對(duì)象之間的填充。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于 0,則引發(fā)異常。

getAroundElementsPadding

public int getAroundElementsPadding()

獲取文本和元素對(duì)象之間的填充。

返回:

返回文本和元素對(duì)象之間的填充。

setTextInputType

public void setTextInputType(int inputType)

設(shè)置 Text 的文本輸入類型。

參數(shù):

參數(shù)名稱 參數(shù)描述
inputType 指示文本輸入類型,如 InputAttribute 中所枚舉。

getTextInputType

public int getTextInputType()

獲取Text的文本輸入類型。

返回:

返回文本輸入類型,如 InputAttribute 中所枚舉。

setRichText

public void setRichText(RichText richText)

設(shè)置要在文本組件中顯示的富文本。

文本組件可以顯示富文本或普通文本。 最新配置生效。

參數(shù):

參數(shù)名稱 參數(shù)描述
richText 指示要在文本組件中顯示的富文本。

Since:

3

getRichText

public RichText getRichText()

獲取文本組件中顯示的富文本。

返回:

返回文本組件中顯示的富文本。

Since:

3

setText

public void setText(String text)

設(shè)置要在文本組件中顯示的文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
text 指示要在文本組件中顯示的文本。

setText

public void setText(int resId)

設(shè)置要顯示的文本的資源 ID。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 表示文本的資源ID。

Since:

3

getText

public String getText()

獲取文本組件中顯示的文本。

返回:

返回文本組件中顯示的文本。

setHint

public void setHint(String hint)

設(shè)置文本為空時(shí)顯示的提示文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
hint 指示文本為空時(shí)要顯示的提示文本。

setHint

public void setHint(int resId)

設(shè)置此 Text 為空時(shí)顯示的提示文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 指示提示文本的資源 ID。

Since:

7

getHint

public String getHint()

獲取文本為空時(shí)顯示的提示文本。

返回:

返回文本為空時(shí)要顯示的提示文本。

getEditableString

public String getEditableString()

獲取可編輯文本組件中的文本。 如果文本組件不可編輯,則返回 null。

返回:

返回可編輯文本組件中的文本。

Since:

4

isEditable

public boolean isEditable()

檢查此文本是否可編輯。

返回:

如果文本是可編輯的,則返回 true; 否則返回 false。

Since:

7

setTextSize

public void setTextSize(int size)

為文本設(shè)置指定的字體大小。

參數(shù):

參數(shù)名稱 參數(shù)描述
size 指示要設(shè)置的字體大小。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果 size 參數(shù)值小于 0,則引發(fā)異常。

Since:

3

setTextSize

public void setTextSize(int size, Text.TextSizeType textSizeType)

為具有指定文本大小類型的文本組件設(shè)置文本大小。

參數(shù):

參數(shù)名稱 參數(shù)描述
size 指示文本組件的文本大小。
textSizeType 指示文本大小的類型。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果 size 參數(shù)值小于 0,則引發(fā)異常。

Since:

4

getTextSize

public int getTextSize()

獲取文本組件的文本大小。

返回:

返回文本大小。

getTextSize

public int getTextSize(Text.TextSizeType textSizeType)

獲取文本的字體大小。

參數(shù):

參數(shù)名稱 參數(shù)描述
textSizeType 表示文本大小的單位。

返回:

返回字體大小。

Since:

4

setTextColor

public void setTextColor(Color color)

設(shè)置文本組件的文本顏色。

參數(shù):

參數(shù)名稱 參數(shù)描述
color 指示文本顏色。

getTextColor

public Color getTextColor()

獲取文本組件的文本顏色。

返回:

返回文本顏色。

setHintColor

public void setHintColor(Color color)

設(shè)置文本組件中提示文本的顏色。

參數(shù):

參數(shù)名稱 參數(shù)描述
color 指示文本組件中提示文本的顏色。

Since:

4

getHintColor

public Color getHintColor()

獲取文本組件中提示文本的顏色。

返回:

返回文本組件中提示文本的顏色。

Since:

4

setTextAlignment

public void setTextAlignment(int textAlignment)

設(shè)置文本組件中的文本對(duì)齊方式。

參數(shù):

參數(shù)名稱 參數(shù)描述
textAlignment 表示文本組件中的文本對(duì)齊方式TextAlignment。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值與 TextAlignment 不對(duì)應(yīng),則引發(fā)異常。

getTextAlignment

public int getTextAlignment()

獲取文本組件中的文本對(duì)齊方式。

返回:

返回文本對(duì)齊方式 TextAlignment。

setTextCursorVisible

public void setTextCursorVisible(boolean visible)

設(shè)置光標(biāo)對(duì)于可編輯文本組件是否可見。

參數(shù):

參數(shù)名稱 參數(shù)描述
visible 指示光標(biāo)對(duì)于可編輯的文本組件是否可見。 true 表示可見; false 表示不可見。

Since:

4

isTextCursorVisible

public boolean isTextCursorVisible()

獲取光標(biāo)對(duì)于可編輯文本組件是否可見。

返回:

如果光標(biāo)對(duì)可編輯文本組件可見,則返回 true; 否則返回 false。

Since:

4

length

public int length()

獲取文本組件中允許的文本長(zhǎng)度。

返回:

返回文本組件中允許的文本長(zhǎng)度。

append

public void append(String text)

將文本字符串附加到文本組件中的現(xiàn)有文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
text 指示要附加的文本字符串。

insert

public void insert(String text)

在光標(biāo)所在位置插入文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
text 指示要插入的文本。

Since:

2

insert

public void insert(String text, int pos)

在指定位置插入文本。 如果 pos 為 AUTO_CURSOR_POSITION,則將文本插入到光標(biāo)所在的位置。

參數(shù):

參數(shù)名稱 參數(shù)描述
text 指示要插入的文本。
pos 指示插入文本的位置。 AUTO_CURSOR_POSITION 值表示從光標(biāo)所在位置插入文本。

Since:

2

delete

public void delete(int length)

刪除光標(biāo)前的文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
length 指示要?jiǎng)h除的文本的長(zhǎng)度。

Since:

2

delete

public void delete(int length, boolean back)

刪除光標(biāo)之前或之后的文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
length 指示要?jiǎng)h除的文本的長(zhǎng)度。
back 指示是否以向后的方式刪除文本。 true 表示刪除光標(biāo)前的文本; false 表示刪除光標(biāo)后的文本。

Since:

2

delete

public void delete(int length, boolean back, int pos)

從指定位置刪除文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
length 指示要?jiǎng)h除的文本的長(zhǎng)度。
back 指示是否以向后的方式刪除文本。 true 表示刪除指定位置之前的文本; false 表示刪除指定位置之后的文本。
pos 指示要?jiǎng)h除文本的位置。 AUTO_CURSOR_POSITION 值表示從光標(biāo)所在位置刪除文本。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于 0,則引發(fā)異常。

Since:

2

setMultipleLine

public void setMultipleLine(boolean multiple)

設(shè)置文本是否在文本組件中多行顯示。

參數(shù):

參數(shù)名稱 參數(shù)描述
multiple 指示文本是否以多行顯示。 true 表示文本多行顯示; false 表示文本不顯示在多行中。

isMultipleLine

public boolean isMultipleLine()

獲取文本是否在文本組件中多行顯示。

返回:

如果文本以多行顯示,則返回 true; 否則返回 false。

setMaxTextLines

public void setMaxTextLines(int maxLines)

設(shè)置文本組件中允許的最大行數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
maxLines 指示文本組件中允許的最大行數(shù)。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于或等于 0,則引發(fā)異常。

Since:

4

getMaxTextLines

public int getMaxTextLines()

獲取文本組件中允許的最大行數(shù)。

返回:

返回文本組件中允許的最大行數(shù)。

Since:

4

setScrollable

public void setScrollable(boolean scrollable)

設(shè)置文本是否可滾動(dòng)。

參數(shù):

參數(shù)名稱 參數(shù)描述
scrollable 指示文本是否可滾動(dòng)。 true 表示文本是可滾動(dòng)的; false 表示文本不可滾動(dòng)。

isScrollable

public boolean isScrollable()

獲取文本在文本組件中是否可滾動(dòng)。 true 表示文本是可滾動(dòng)的; false 表示文本不可滾動(dòng)。

返回:

如果文本是可滾動(dòng)的,則返回 true; 否則返回 false。

setAutoFontSize

public void setAutoFontSize(boolean autoFontSize)

設(shè)置是否自動(dòng)調(diào)整文本大小以填充組件。

參數(shù):

參數(shù)名稱 參數(shù)描述
autoFontSize 指示是否自動(dòng)調(diào)整文本大小以填充組件。 true 表示自動(dòng)調(diào)整文本大小以填充到組件內(nèi); false 表示不會(huì)自動(dòng)調(diào)整文本大小以填充組件。

setAutoFontSize

public void setAutoFontSize(boolean autoFontSize, boolean userSizeFirst)

設(shè)置是否自動(dòng)調(diào)整字體大小以填充組件內(nèi),以及是否在啟用自動(dòng)字體大小適應(yīng)之前嘗試指定的字體大小。

建議您在啟用 userSizeFirst 之前啟用 autoFontSize。

參數(shù):

參數(shù)名稱 參數(shù)描述
autoFontSize 指示是否啟用自動(dòng)字體大小調(diào)整。 true 表示自動(dòng)調(diào)整字體大小以填充到組件內(nèi),以便顯示完整的文本內(nèi)容; false 表示相反。
userSizeFirst userSizeFirst 指示是否在啟用自動(dòng)字體大小調(diào)整之前嘗試指定的字體大小。 true 表示為布局嘗試指定的字體大小。 如果指定的字體大小不允許在組件中顯示所有文本內(nèi)容,則會(huì)選擇由 setAutoFontSizeRule(int,int,int) 設(shè)置的合適字體大小。 false 表示由 setAutoFontSizeRule(int,int ,int) 設(shè)置的合適字體大小將直接用于布局,而不嘗試指定的字體大小。

Since:

3

setLineSpacing

public void setLineSpacing(float add, float mult)

設(shè)置文本組件的行距。

每條線的高度乘以 mult,并加上 add。 例如,當(dāng)height為1,mult為2,add為3時(shí),行距為5。

參數(shù):

參數(shù)名稱 參數(shù)描述
add 表示要添加到除最后一行之外的每一行的高度的值。
mult 表示要乘以每行高度的值,最后一行除外。

getNumOfFontHeight

public float getNumOfFontHeight()

獲取行距乘數(shù),它在文本組件中的行之間提供額外的間距。

返回:

返回行距乘數(shù)。

Since:

4

getAdditionalLineSpacing

public float getAdditionalLineSpacing()

獲取添加到文本組件中每行高度的額外間距。

返回:

返回添加到每行高度的額外間距。

Since:

4

isAdjustInputPanel

public boolean isAdjustInputPanel()

獲取在彈出輸入法面板時(shí)是否開啟自動(dòng)文本組件重新布局。

返回:

如果啟用了自動(dòng)文本組件重新布局,則返回 true; 否則返回 false。

Since:

3

setAdjustInputPanel

public void setAdjustInputPanel(boolean adjust)

設(shè)置當(dāng)軟輸入面板彈出或隱藏時(shí)布局是否應(yīng)調(diào)整大小。

參數(shù):

參數(shù)名稱 參數(shù)描述
adjust 指示布局是否應(yīng)調(diào)整可編輯文本組件的大小。 true 表示調(diào)整大小; false 表示不是。

setMaxTextHeight

public void setMaxTextHeight(int maxTextHeight)

設(shè)置文本的最大高度。

此方法用于將文本高度設(shè)置為 MATCH_CONTENT 的情況。

參數(shù):

參數(shù)名稱 參數(shù)描述
maxTextHeight 指示文本的最大高度。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于 0,則引發(fā)異常。

Since:

4

getMaxTextHeight

public int getMaxTextHeight()

獲取文本的最大高度。

返回:

返回文本的最大高度。

Since:

4

setMinTextHeight

public void setMinTextHeight(int minHeight)

設(shè)置此文本的最小高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
minHeight 指示要設(shè)置的最小高度。

Since:

7

setMaxTextWidth

public void setMaxTextWidth(int maxTextWidth)

設(shè)置文本的最大寬度。

此方法用于將文本寬度設(shè)置為 MATCH_CONTENT 的情況。

參數(shù):

參數(shù)名稱 參數(shù)描述
maxTextWidth 指示文本的最大寬度。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值小于 0,則引發(fā)異常。

Since:

4

getMaxTextWidth

public int getMaxTextWidth()

獲取文本的最大寬度。

返回:

返回文本的最大寬度。

Since:

4

onRtlChanged

protected void onRtlChanged(Component.LayoutDirection layoutDirection)

從類復(fù)制的描述:組件

在更改任何 RTL 屬性時(shí)調(diào)用。

覆蓋:

類組件中的 onRtlChanged

參數(shù):

參數(shù)名稱 參數(shù)描述
layoutDirection 表示當(dāng)前布局方向的值。

setBubbleSize

public void setBubbleSize(int width, int height)

設(shè)置顯示文本的氣泡框的寬度和高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 指示要設(shè)置的氣泡框的寬度,以像素為單位。
height 指示要設(shè)置的氣泡框的高度,以像素為單位。

Since:

4

setBubbleWidth

public void setBubbleWidth(int width)

設(shè)置文本氣泡框的寬度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 表示要設(shè)置的寬度。

Since:

4

setBubbleHeight

public void setBubbleHeight(int height)

設(shè)置文本氣泡框的高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
height 表示要設(shè)置的高度。

Since:

4

getBubbleWidth

public int getBubbleWidth()

獲取文本氣泡框的寬度。

返回:

返回氣泡框的寬度。

Since:

4

getBubbleHeight

public int getBubbleHeight()

獲取文本氣泡框的高度。

返回:

返回氣泡框的高度。

Since:

4

setLeftBubbleSize

public void setLeftBubbleSize(int width, int height)

設(shè)置顯示文本的氣泡框左側(cè)填充區(qū)域的寬度和高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 指示要設(shè)置的氣泡框的寬度,以像素為單位。
height 指示要設(shè)置的氣泡框的高度,以像素為單位。

Since:

4

setLeftBubbleWidth

public void setLeftBubbleWidth(int width)

設(shè)置文本左側(cè)氣泡框的寬度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 表示要設(shè)置的寬度。

Since:

4

setLeftBubbleHeight

public void setLeftBubbleHeight(int height)

設(shè)置文本左側(cè)氣泡框的高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
height 表示要設(shè)置的高度。

Since:

4

getSelectionLeftBubbleWidth

public int getSelectionLeftBubbleWidth()

獲取所選氣泡框左側(cè)填充區(qū)域的寬度。

返回:

返回寬度。

Since:

4

getSelectionLeftBubbleHeight

public int getSelectionLeftBubbleHeight()

獲取所選氣泡框左側(cè)填充區(qū)域的高度。

返回:

返回高度。

Since:

4

setRightBubbleSize

public void setRightBubbleSize(int width, int height)

設(shè)置顯示文本的氣泡框右側(cè)填充區(qū)域的寬度和高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 指示要設(shè)置的氣泡框的寬度,以像素為單位。
height 指示要設(shè)置的氣泡框的高度,以像素為單位。

Since:

4

setRightBubbleWidth

public void setRightBubbleWidth(int width)

設(shè)置文本右側(cè)氣泡框的寬度。

參數(shù):

參數(shù)名稱 參數(shù)描述
width 表示要設(shè)置的寬度。

Since:

4

setRightBubbleHeight

public void setRightBubbleHeight(int height)

設(shè)置文本右側(cè)氣泡框的高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
height 表示要設(shè)置的高度。

Since:

4

getSelectionRightBubbleWidth

public int getSelectionRightBubbleWidth()

獲取所選氣泡框右側(cè)填充區(qū)域的寬度。

返回:

返回寬度。

Since:

4

getSelectionRightBubbleHeight

public int getSelectionRightBubbleHeight()

獲取所選氣泡框右側(cè)填充區(qū)域的高度。

返回:

返回高度。

Since:

4

setSelectionColor

public void setSelectionColor(Color color)

設(shè)置選定文本的顏色。

參數(shù):

參數(shù)名稱 參數(shù)描述
color 指示要設(shè)置的選定文本的顏色。

Since:

4

getSelectionColor

public Color getSelectionColor()

獲取選定文本的顏色。

返回:

返回所選文本的顏色。

Since:

4

getSelectionStart

public int getSelectionStart()

獲取選擇邊的起點(diǎn)。

返回:

返回選擇邊緣的起點(diǎn)。

Since:

7

getSelectionEnd

public int getSelectionEnd()

獲得選擇邊的結(jié)束。

返回:

返回選擇邊緣的結(jié)束。

Since:

7

setSelection

public boolean setSelection(int start, int end)

設(shè)置此文本的選擇范圍。

參數(shù):

參數(shù)名稱 參數(shù)描述
start 指示選擇范圍的起始位置。
end 指示選擇范圍的結(jié)束位置。

返回:

如果選擇范圍設(shè)置成功,則返回 true; 否則返回 false。

Since:

7

setBubbleElement

public void setBubbleElement(Element element)

為光標(biāo)所在的氣泡設(shè)置一個(gè) Element 對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
element 指示要設(shè)置的 Element 對(duì)象。

Since:

4

setBubbleElement

public void setBubbleElement(int resId)

為光標(biāo)所在的氣泡設(shè)置一個(gè) Element 對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 指示元素的資源ID。

Since:

7

setSelectionLeftBubbleElement

public void setSelectionLeftBubbleElement(Element element)

設(shè)置要為左側(cè)氣泡顯示的元素對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
element 指示要顯示的元素。

Since:

4

setSelectionLeftBubbleElement

public void setSelectionLeftBubbleElement(int resId)

設(shè)置要為左側(cè)氣泡顯示的元素對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 指示左氣泡元素的資源 ID。

Since:

7

setSelectionRightBubbleElement

public void setSelectionRightBubbleElement(Element element)

設(shè)置要為右側(cè)氣泡顯示的元素對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
element 指示要顯示的元素。

Since:

4

setSelectionRightBubbleElement

public void setSelectionRightBubbleElement(int resId)

設(shè)置要為右側(cè)氣泡顯示的元素對(duì)象。

參數(shù):

參數(shù)名稱 參數(shù)描述
resId 表示右Bubble元素的資源ID。

Since:

7

getBubbleElement

public Element getBubbleElement()

獲取光標(biāo)所在氣泡框的Element對(duì)象。

返回:

返回元素對(duì)象。

Since:

4

getSelectionLeftBubbleElement

public Element getSelectionLeftBubbleElement()

獲取顯示在選中氣泡框左側(cè)內(nèi)邊距區(qū)域的 Element 對(duì)象。

返回:

返回元素對(duì)象。

Since:

4

getSelectionRightBubbleElement

public Element getSelectionRightBubbleElement()

獲取顯示在選中氣泡框右側(cè)內(nèi)邊距區(qū)域的 Element 對(duì)象。

返回:

返回元素對(duì)象。

Since:

4

setCursorPosition

public boolean setCursorPosition(int position)

設(shè)置文本的光標(biāo)位置。

參數(shù):

參數(shù)名稱 參數(shù)描述
position 光標(biāo)位置的偏移量。

返回:

成功設(shè)置為 true,否則為 false。

Since:

7

setFadeEffectBoundaryWidth

public void setFadeEffectBoundaryWidth(int width)

設(shè)置文本的淡入淡出效果區(qū)域的邊界寬度。

覆蓋:

類 Component 中的 setFadeEffectBoundaryWidth

參數(shù):

參數(shù)名稱 參數(shù)描述
width 指示要設(shè)置的邊界寬度,以像素為單位。

Since:

4

getFadeEffectBoundaryWidth

public int getFadeEffectBoundaryWidth()

獲取文本淡化效果區(qū)域的邊界寬度。

覆蓋:

類 Component 中的 getFadeEffectBoundaryWidth

返回:

返回文本淡入淡出區(qū)域的邊界寬度。

Since:

4

setPaddingForText

public void setPaddingForText(boolean hasPadding)

設(shè)置文本是否有額外的填充空間。

此方法僅對(duì)單行文本有效。

參數(shù):

參數(shù)名稱 參數(shù)描述
hasPadding 指定文本是否有額外的填充空間。 true 表示文本的高度在上下邊框之間,false 表示高度在字體上升和下降之間。

Since:

4

getPaddingForText

public boolean getPaddingForText()

檢查文本是否有額外的填充空間。

返回:

如果文本的高度在上下邊框之間,則返回 true; 如果高度在字體上升和下降之間,則返回 false。

Since:

4

getFontVariations

public String getFontVariations()

獲取字體變化設(shè)置。

返回:

如果獲得,則返回當(dāng)前的字體變化設(shè)置; 如果未指定任何字符串,則返回一個(gè)空字符串。

Since:

5

setFontVariations

public boolean setFontVariations(String variation)

設(shè)置 TrueType 或 OpenType 字體變體設(shè)置。 設(shè)置字符串由多對(duì)標(biāo)簽和樣式值組成。 標(biāo)簽必須包含精確的四個(gè) ASCII 字符,并且必須用單引號(hào)或雙引號(hào)括起來。 如果包含 U+0020..U+007E 以外的字符,則無效。 如果指定的標(biāo)簽名稱尚未在字體中定義,則設(shè)置將被忽略。

下面顯示了將字體寬度和粗細(xì)設(shè)置為 100 的示例代碼。

    text.setFontVariations("'wdth' 100,'wght' 100");  

參數(shù):

參數(shù)名稱 參數(shù)描述
variation 表示字體變化設(shè)置。

返回:

如果傳遞的變體對(duì)當(dāng)前字體有效,則返回 true; 如果傳遞的變體是空字符串或不符合定義的規(guī)范,則返回 false。

Since:

5

getLineCount

public int getLineCount()

獲取此文本中的行數(shù)。

返回:

返回行數(shù)。

Since:

7

getLineHeight

public int getLineHeight()

獲取此 Text 的行間高度。

返回:

返回行之間的高度。

Since:

7

getCombinedPaddingStart

public int getCombinedPaddingStart()

獲取此文本開頭的組合填充。

如果文本以組件開頭,則組合內(nèi)邊距包括組件的寬度和組件內(nèi)邊距。

返回:

返回文本開頭的組合填充,以像素為單位。

Since:

7

getCombinedPaddingTop

public int getCombinedPaddingTop()

獲取此文本頂部的組合填充。

如果文本頂部有組件,則組合的 padding 包括組件的高度和組件的 padding。

返回:

返回文本頂部的組合填充,以像素為單位。

Since:

7

getCombinedPaddingEnd

public int getCombinedPaddingEnd()

獲取文本末尾的組合填充。

如果文本末尾有組件,則組合填充包括組件的寬度和組件填充。

返回:

返回文本末尾的組合填充,以像素為單位。

Since:

7

getCombinedPaddingBottom

public int getCombinedPaddingBottom()

獲取此文本底部的組合填充。

如果文本底部有組件,則組合的 padding 包括組件的高度和組件的 padding。

返回:

返回文本底部的組合填充,以像素為單位。

Since:

7

getCombinedPaddingLeft

public int getCombinedPaddingLeft()

獲取此文本左側(cè)的組合填充。

如果文本左側(cè)有組件,則合并的 padding 包括組件的寬度和組件的 padding。

返回:

返回文本左側(cè)的組合填充,以像素為單位。

Since:

7

getCombinedPaddingRight

public int getCombinedPaddingRight()

獲取此文本右側(cè)的組合填充。

如果文本右側(cè)有組件,則組合的 padding 包括組件的寬度和組件的 padding。

返回:

返回文本右側(cè)的組合填充,以像素為單位。

Since:

7

getTextToTopSpace

public int getTextToTopSpace()

獲取顯示的文本頂部到文本組件頂部的距離。

返回:

返回從顯示文本頂部到文本組件頂部的距離,以像素為單位。

Since:

7

getTextToBottomSpace

public int getTextToBottomSpace()

獲取顯示的文本底部到文本組件底部的距離。

返回:

返回從顯示文本底部到文本組件底部的距離,以像素為單位。

Since:

7

setHyperLinkColor

public void setHyperLinkColor(Color color)

設(shè)置文本中鏈接的顏色。

參數(shù):

參數(shù)名稱 參數(shù)描述
color 文本鏈接的顏色。

Since:

7

setHyperLinkClickable

public void setHyperLinkClickable(boolean isClickable)

設(shè)置此文本中超鏈接的可點(diǎn)擊性。

參數(shù):

參數(shù)名稱 參數(shù)描述
isClickable 指定是否將超鏈接設(shè)置為可單擊。 值 true 表示將超鏈接設(shè)置為可點(diǎn)擊,false 表示相反。

Since:

7

isHyperLinkClickable

public boolean isHyperLinkClickable()

檢查此文本中的超鏈接是否可單擊。

返回:

如果超鏈接是可點(diǎn)擊的,則返回 true; 否則返回 false。

Since:

7

getUrls

public ListUrlRichStyle getUrls()

獲取此文本中的超鏈接列表。

返回:

返回超鏈接列表。

Since:

7

getPrimaryLocale

public Locale getPrimaryLocale()

獲取此文本的默認(rèn)語言環(huán)境。

返回:

返回此文本的默認(rèn)語言環(huán)境。

Since:

7

setPrimaryLocale

public void setPrimaryLocale(Locale locale)

設(shè)置用于繪制此文本的區(qū)域設(shè)置。

參數(shù):

參數(shù)名稱 參數(shù)描述
locale 指示要設(shè)置的區(qū)域設(shè)置。 該值不能為空。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果 locale 的值為 null,則引發(fā)此異常。

Since:

7

getLocales

public LocaleProfile getLocales()

獲取此 Text 的默認(rèn) LocaleProfile。

返回:

返回此文本的默認(rèn) LocaleProfile。

Since:

7

setLocales

public void setLocales(LocaleProfile locales)

設(shè)置用于繪制此文本的 LocaleProfile。

參數(shù):

參數(shù)名稱 參數(shù)描述
locales 表示一組語言環(huán)境。 該值不能為空。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果 locales 的值為 null,則引發(fā)此異常。

Since:

7

getInputMethodLocales

public LocaleProfile getInputMethodLocales()

獲取此文本的建議 LocaleProfile。

返回:

如果獲得,則返回建議的 LocaleProfile; 如果沒有配置建議的 LocaleProfile,則返回 null。

Since:

7

setInputMethodLocales

public void setInputMethodLocales(LocaleProfile locales)

為此文本設(shè)置建議的 LocaleProfile。

當(dāng)此文本具有焦點(diǎn)時(shí),建議的語言環(huán)境信息將報(bào)告給輸入法。

參數(shù):

參數(shù)名稱 參數(shù)描述
locales 指示要設(shè)置的建議 LocaleProfile。

Since:

7

getFontFeatures

public String getFontFeatures()

獲取字體功能設(shè)置。

格式與 CSS font-feature-settings 屬性的格式相同。

返回:

返回當(dāng)前字體功能設(shè)置。

Since:

7

setFontFeatures

public void setFontFeatures(String settings)

設(shè)置字體特征。

格式與 CSS font-feature-settings 屬性的格式相同。

參數(shù):

參數(shù)名稱 參數(shù)描述
settings 指示由 CSS 兼容字符串表示的字體功能設(shè)置。

Since:

7

getTextShadowColor

public Color getTextShadowColor()

獲取文本陰影的顏色。

返回:

文本陰影的顏色。

Since:

7

setTextShadow

public void setTextShadow(float offsetX, float offsetY, float radius, Color color)

設(shè)置此文本的陰影。

參數(shù):

參數(shù)名稱 參數(shù)描述
offsetX 文字陰影的水平偏移。
offsetY 文字陰影的垂直偏移。
radius 文字陰影的模糊半徑。
color 指示要設(shè)置的陰影顏色。

Since:

7

getTextShadowOffsetX

public float getTextShadowOffsetX()

獲取文本陰影的水平偏移量。

返回:

文字陰影的水平偏移。

Since:

7

getTextShadowOffsetY

public float getTextShadowOffsetY()

獲取文本陰影的垂直偏移量。

返回:

文字陰影的垂直偏移。

Since:

7

getTextShadowRadius

public float getTextShadowRadius()

獲取文本陰影的模糊半徑。

返回:

文字陰影的模糊半徑。

Since:

7

setHyphenationStrategy

public void setHyphenationStrategy(TextLayout.HyphenationStrategy strategy)

設(shè)置此文本的自動(dòng)斷字策略。

參數(shù):

參數(shù)名稱 參數(shù)描述
strategy 表示要設(shè)置的自動(dòng)斷字策略。

Since:

7

getHyphenationStrategy

public TextLayout.HyphenationStrategy getHyphenationStrategy()

獲取該文本的自動(dòng)斷字策略。

返回:

返回自動(dòng)斷字的策略。

Since:

7

moveToPosition

public boolean moveToPosition(int offset)

根據(jù)指定的偏移量將字符移動(dòng)到可見位置。

此方法用于滾動(dòng)文本。 如果文本沒有滾動(dòng),則返回 false。

參數(shù):

參數(shù)名稱 參數(shù)描述
offset 表示字符位置的偏移量。 偏移值只能是非負(fù)整數(shù),任何負(fù)數(shù)都被視為 0。

返回:

如果文本滾動(dòng),則返回 true; 否則返回 false。

Since:

7

getLetterSpacing

public float getLetterSpacing()

獲取文本字母之間的間距。

返回:

返回文本字母之間的間距。

Since:

7

getBaseLine

public int getBaseLine(int line)

獲取目標(biāo)線基線的 y 坐標(biāo)。

參數(shù):

參數(shù)名稱 參數(shù)描述
line 表示目標(biāo)行號(hào),范圍從0到總行號(hào)減1??梢允褂胓etLineCount()獲取總行號(hào)。

返回:

返回目標(biāo)線基線的 y 坐標(biāo)。

Since:

7

getBoundingRect

public void getBoundingRect(int line, Rect bounding)

獲取目標(biāo)線的邊界矩形。

參數(shù):

參數(shù)名稱 參數(shù)描述
line 表示目標(biāo)行號(hào),范圍從0到總行號(hào)減1。可以使用getLineCount()獲取總行號(hào)。
bounding 表示目標(biāo)線的位置,包括左側(cè)的x坐標(biāo)、頂部的y坐標(biāo)、右側(cè)的x坐標(biāo)和底部的y坐標(biāo)。

Since:

7

getMinTextHeight

public int getMinTextHeight()

獲取此 Text 的最小高度。

返回:

返回此文本的最小高度。

Since:

7

setMinTextLines

public void setMinTextLines(int minLines)

設(shè)置此文本的最小行數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
minLines 指示要設(shè)置的最小行數(shù)。

Since:

7

getMinTextLines

public int getMinTextLines()

獲取此文本中的最小行數(shù)。

返回:

如果獲得,則返回最小行數(shù); 否則返回 -1。

Since:

7

getOffsetByCoordinates

public int getOffsetByCoordinates(float x, float y)

獲取距離指定位置最近的字符偏移量。

參數(shù):

參數(shù)名稱 參數(shù)描述
x 表示指定位置的 x 坐標(biāo)。
y 表示指定位置的 y 坐標(biāo)。

返回:

返回最接近指定位置的字符偏移量。

Since:

7

getFontFamilyType

public Text.FontFamilyType getFontFamilyType()

獲取此 Text 的字體系列類型。

返回:

返回此文本的字體系列類型。

Since:

7

setFontFamilyType

public void setFontFamilyType(Text.FontFamilyType type)

設(shè)置此文本的字體系列。

參數(shù):

參數(shù)名稱 參數(shù)描述
type 指示要設(shè)置的字體系列變體。

Since:

7

getMaxWidthInEms

public int getMaxWidthInEms()

獲取此文本的最大寬度,以 em 為單位。

返回:

如果獲得,則返回最大寬度(以 em 為單位); 如果未配置最大寬度,則返回 -1。

Since:

7

getMinWidthInEms

public int getMinWidthInEms()

獲取此文本的最小寬度,以 em 為單位。

返回:

如果獲得,則返回最小寬度(以 em 為單位); 如果未配置最小寬度,則返回 -1。

Since:

7

setTextWidthInEms

public void setTextWidthInEms(int ems)

設(shè)置此文本的寬度,以 em 為單位。

參數(shù):

參數(shù)名稱 參數(shù)描述
ems 表示要設(shè)置的寬度,單位為 em。

Since:

7

setMaxWidthInEms

public void setMaxWidthInEms(int maxEms)

設(shè)置此文本的最大寬度,以 em 為單位。

參數(shù):

參數(shù)名稱 參數(shù)描述
maxEms 表示要設(shè)置的最大寬度,以 em 為單位。

Since:

7

setMinWidthInEms

public void setMinWidthInEms(int minEms)

設(shè)置此文本的最小寬度,以 em 為單位。

參數(shù):

參數(shù)名稱 參數(shù)描述
minEms 表示要設(shè)置的最小寬度,以 em 為單位。

Since:

7

getJustifyStrategy

public TextLayout.JustifyStrategy getJustifyStrategy()

獲取文本對(duì)齊策略。

返回:

返回文本對(duì)齊策略。

Since:

7

setJustifyStrategy

public void setJustifyStrategy(TextLayout.JustifyStrategy strategy)

設(shè)置文本對(duì)齊策略。

參數(shù):

參數(shù)名稱 參數(shù)描述
strategy 表示文本對(duì)齊策略。

Since:

7

setLetterSpacing

public void setLetterSpacing(float spacing)

設(shè)置文本字母之間的間距。

參數(shù):

參數(shù)名稱 參數(shù)描述
spacing 指示文本字母之間的間距。

Since:

7

setLineHeight

public void setLineHeight(int lineHeight)

設(shè)置此文本的行之間的高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
lineHeight 指示行之間的高度,以像素為單位。

Since:

7

setTextHeight

public void setTextHeight(int pixels)

設(shè)置此文本的固定高度。

參數(shù):

參數(shù)名稱 參數(shù)描述
pixels 指示要設(shè)置的高度,以像素為單位。

Since:

7

setLines

public void setLines(int lines)

設(shè)置此文本的行數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
lines 指示要設(shè)置的行數(shù)。

Since:

7

getLineBreakStrategy

public TextLayout.LineBreakStrategy getLineBreakStrategy()

獲取該文本的換行策略。

返回:

返回?fù)Q行策略。

Since:

7

setLineBreakStrategy

public void setLineBreakStrategy(TextLayout.LineBreakStrategy strategy)

設(shè)置此文本的換行策略。

參數(shù):

參數(shù)名稱 參數(shù)描述
strategy 表示要設(shè)置的換行策略。

Since:

7

lockEditingState

public void lockEditingState()

鎖定輸入法并開始文本編輯。

Since:

7

unlockEditingState

public void unlockEditingState()

解鎖輸入法并結(jié)束文本編輯。

Since:

7

onLockEditingState

public void onLockEditingState()

當(dāng)輸入法被鎖定時(shí)調(diào)用。

Since:

7

onUnlockEditingState

public void onUnlockEditingState()

當(dāng)輸入法解鎖時(shí)調(diào)用。

Since:

7

isFocusedByTouch

public boolean isFocusedByTouch()

當(dāng)你觸摸它時(shí)檢查這個(gè)文本是否有焦點(diǎn)。

返回:

如果此 Text 具有焦點(diǎn),則返回 true; 否則返回 false。

Since:

7

isTextSelectable

public boolean isTextSelectable()

檢查是否可以選擇此文本。

返回:

如果可以選擇文本,則返回 true; 否則返回 false。

Since:

7

adjustCursorPosition

public boolean adjustCursorPosition()

檢查光標(biāo)是否可以移動(dòng)到可見位置。

返回:

如果光標(biāo)可以移動(dòng)到可見位置,則返回 true; 否則返回 false。

Since:

7

isAutoSelectEnabled

public boolean isAutoSelectEnabled()

獲取文本獲得焦點(diǎn)時(shí)是否選擇所有文本。

返回:

如果文本獲得焦點(diǎn)時(shí)將選擇所有文本,則返回 true; 否則返回 false。

Since:

7

setAutoSelectEnabled

public void setAutoSelectEnabled(boolean isSelectAll)

設(shè)置 thisText 有焦點(diǎn)時(shí)是否選擇所有文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
isSelectAll 指定當(dāng)此 Text 具有焦點(diǎn)時(shí)是否選擇所有文本。 true 表示選擇所有文本,false 表示相反。

Since:

7

setTextSelectable

public void setTextSelectable(boolean isSelectable)

設(shè)置此文本是否可選。

參數(shù):

參數(shù)名稱 參數(shù)描述
isSelectable 指定文本是否可選。 值 true 表示文本是可選擇的,false 表示相反。

Since:

7

getInputFilters

public InputFilter[] getInputFilters()

獲取輸入過濾器列表。

返回:

返回輸入過濾器列表。

Since:

7

setInputFilters

public void setInputFilters(InputFilter[] filters)

設(shè)置文本的輸入過濾器列表。

參數(shù):

參數(shù)名稱 參數(shù)描述
filters 輸入過濾器列表。

Throws:

Throw名稱 Throw描述
IllegalArgumentException 如果參數(shù)值為 null,則引發(fā)此異常。

Since:

7

getEditorAction

public int getEditorAction()

獲取編輯器動(dòng)作。

返回:

返回編輯器操作。

Since:

7

getEditorActionText

public CharSequence getEditorActionText()

獲取編輯器操作文本。

返回:

返回編輯器操作文本。

Since:

7

setEditorActionText

public void setEditorActionText(CharSequence text, int action)

設(shè)置編輯器操作文本。

當(dāng)文本字段獲得焦點(diǎn)時(shí),該信息將報(bào)告給輸入法。

參數(shù):

參數(shù)名稱 參數(shù)描述
text 指示發(fā)送到輸入法的自定義編輯器操作文本。
action 指示發(fā)送到輸入法的自定義編輯器操作。

Since:

7

setExtraInputData

public void setExtraInputData(PacMap data)

為此文本設(shè)置額外的輸入數(shù)據(jù)。

當(dāng)文本獲得焦點(diǎn)時(shí),會(huì)通過數(shù)據(jù)上報(bào)給輸入法。

參數(shù):

參數(shù)名稱 參數(shù)描述
data 指示提供給輸入法的 PacMap 對(duì)象。

Since:

7

getCustomInputMethodOptions

public String getCustomInputMethodOptions()

獲取自定義輸入法選項(xiàng)。

返回:

返回自定義輸入法選項(xiàng)。

Since:

7

setCustomInputMethodOptions

public void setCustomInputMethodOptions(String options)

設(shè)置此文本的自定義輸入法選項(xiàng)。

如果文本連接到輸入法,自定義輸入法選項(xiàng)將被發(fā)送到輸入法。

參數(shù):

參數(shù)名稱 參數(shù)描述
options 指示要設(shè)置的自定義輸入法選項(xiàng)。

Since:

7

setTextConversion

public void setTextConversion(Text.ConversionType conversionType)

設(shè)置此文本的 ConversionType。

轉(zhuǎn)換僅用于文本顯示,不會(huì)改變文本內(nèi)容。

參數(shù):

參數(shù)名稱 參數(shù)描述
conversionType 表示轉(zhuǎn)換類型。

Since:

7

getTextConversion

public Text.ConversionType getTextConversion()

獲取此文本的 ConversionType。

默認(rèn)轉(zhuǎn)換類型為 ConversionType#NONE。

返回:

返回轉(zhuǎn)換類型。

Since:

7

isAllUpperCase

public boolean isAllUpperCase()

檢查應(yīng)用于此文本的 ConversionType 是否設(shè)置為 ConversionType#ALL_UPPERCASE。

返回:

如果 ConversionType 設(shè)置為 ConversionType#ALL_UPPERCASE,則返回 true; 否則返回 false。

Since:

7

isInputMethodActive

public boolean isInputMethodActive()

檢查此 Text 是否是當(dāng)前輸入法的目標(biāo)。

返回:

如果文本是當(dāng)前輸入法的目標(biāo),則返回 true; 否則為 false。

Since:

7

onTextEditorAction

public boolean onTextEditorAction(int actionCode)

在處理指定編輯器操作的更改事件時(shí)調(diào)用。

參數(shù):

參數(shù)名稱 參數(shù)描述
actionCode 指示編輯器操作。 例如,InputAttribute#ENTER_KEY_TYPE_GO 表示“開始”動(dòng)作,InputAttribute#ENTER_KEY_TYPE_SEND 表示“發(fā)送”動(dòng)作。

返回:

如果事件被處理,則返回 true; 否則返回 false。

Since:

7

isSoftInputVisibleOnFocus

public boolean isSoftInputVisibleOnFocus()

檢查當(dāng)此文本獲得焦點(diǎn)時(shí)軟輸入是否可見。

默認(rèn)值是true。

返回:

如果軟輸入可見,則返回 true; 否則返回 false。

Since:

7

setSoftInputVisibleOnFocus

public void setSoftInputVisibleOnFocus(boolean isShow)

設(shè)置當(dāng)此文本獲得焦點(diǎn)時(shí)是否使軟輸入可見。

參數(shù):

參數(shù)名稱 參數(shù)描述
isShow 指定是否使軟輸入可見。 值 true 表示使軟輸入可見,false 表示相反。 默認(rèn)值是true。

Since:

7

getEditingText

public boolean getEditingText(EditingCapability request, EditingText text)

獲取可編輯的文本。

參數(shù):

參數(shù)名稱 參數(shù)描述
request 表示來自輸入法的請(qǐng)求。
text 指示要檢查的文本。

返回:

如果獲取到可編輯文本,則返回 true; 否則返回 false。

Since:

7

setEditable

public void setEditable(boolean isEditable)

設(shè)置此文本的可編輯性。

參數(shù):

參數(shù)名稱 參數(shù)描述
isEditable 指定是否將文本設(shè)置為可編輯。 值 true 表示將文本設(shè)置為可編輯,false 表示相反。

Since:

7

getExtraInputData

public PacMap getExtraInputData(boolean isCreate)

獲取發(fā)送到輸入法的額外輸入數(shù)據(jù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
isCreate 指定數(shù)據(jù)不存在時(shí)是否創(chuàng)建數(shù)據(jù)。 值 true 表示創(chuàng)建數(shù)據(jù),false 表示相反。

返回:

如果獲得,則返回提供給輸入法的 PacMap 對(duì)象; 否則返回 null。

Since:

7

onCustomInputMethodCommand

public boolean onCustomInputMethodCommand(String action, PacMap data)

由框架調(diào)用以響應(yīng)來自輸入法的自定義命令。

默認(rèn)情況下,此方法不執(zhí)行任何操作。

參數(shù):

參數(shù)名稱 參數(shù)描述
action 指示命令的名稱。
data 指示命令的 PacMap 對(duì)象。

返回:

如果對(duì)命令執(zhí)行操作,則返回 true; 否則返回 false。

Since:

7

setMaxCharacters

public void setMaxCharacters(int maxValue)

設(shè)置此文本的最大字符數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
maxValue 表示最大字符數(shù)。

Since:

7

isFallbackFontMetricsEnabled

public boolean isFallbackFontMetricsEnabled()

檢查是否為后備字體啟用了上升或下降指標(biāo)。

默認(rèn)值是true。

返回:

如果為后備字體啟用上升或下降指標(biāo),則返回 true; 否則返回 false。

Since:

7

setFallbackFontMetricsEnabled

public void setFallbackFontMetricsEnabled(boolean isEnable)

設(shè)置是否為后備字體啟用上升或下降指標(biāo)。

參數(shù):

參數(shù)名稱 參數(shù)描述
isEnable 指定是否為后備字體啟用上升或下降度量。 值 true 表示啟用后備字體的上升或下降指標(biāo),而 false 表示相反。 默認(rèn)值是true。

Since:

7

setTextDirectionStrategy

public void setTextDirectionStrategy(BidiAnalyzer.BidiStrategy strategy)

設(shè)置文本方向策略。

參數(shù):

參數(shù)名稱 參數(shù)描述
strategy 指示確定文本方向的策略。

Since:

7

getTextDirectionStrategy

public BidiAnalyzer.BidiStrategy getTextDirectionStrategy()

獲取文本方向策略。

返回:

返回文本方向策略。

Since:

7

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)