树叶云鸿蒙OS教程:鸿蒙OS TickTimer

TickTimer

java.lang.Object

|—ohos.agp.components.Component

|—|—ohos.agp.components.Text

|—|—|—ohos.agp.components.TickTimer

public class TickTimer
extends Text

实现简单的计时器功能并继承自 Text。

此类设置一个从指定的基准时间向上或向下计数的计时器。 计时器每秒更新一次。

Since:

3

嵌套类摘要

修饰符和类型描述
static interfaceTickTimer.TickListener监听定时器的增量事件。
从类 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
从类 ohos.agp.components.Text 继承的嵌套类/接口
Text.ConversionType, Text.EditorActionListener, Text.FontFamilyType, Text.TextColorObserver, Text.TextObserver, Text.TextSizeObserver, Text.TextSizeType, Text.TruncationMode

字段摘要

修饰符和类型字段描述
protected TickTimer.TickListenermTickListener存储 tick 监听器。
从类 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
从类 ohos.agp.components.Text 继承的字段
AUTO_CURSOR_POSITION, AUTO_SCROLLING_FOREVER

构造函数摘要

构造函数描述
TickTimer(Context context)用于使用默认属性集和样式创建 TickTimer 实例的默认构造函数。
TickTimer(Context context, AttrSet attrSet)用于在解析 XML 文件后使用指定的属性集和默认样式创建 TickTimer 实例的构造函数。
TickTimer(Context context, AttrSet attrSet, String styleName)用于在 XML 文件解析后使用指定的属性集和指定的样式创建 TickTimer 实例的构造函数。

方法总结

修饰符和类型方法描述
longgetBaseTime()获取基准时间。
StringgetFormat()获取定时器的时间格式。
booleanisCountDown()指示计时器是从基准时间开始计数还是从基准时间开始计数。
voidsetBaseTime(long base)设置定时器的基准时间。
voidsetCountDown(boolean countDown)设置计时器是从基准时间开始计数还是从基准时间开始计数。
voidsetFormat(String format)设置 UI 上显示的时间格式。
voidsetTickListener(TickTimer.TickListener listener)设置 tick 监听器。
voidstart()启动计时器。
voidstop()停止计时器。
从类 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
从类 ohos.agp.components.Text 继承的方法
addTextObserver, adjustCursorPosition, append, delete, delete, delete, getAdditionalLineSpacing, getAroundElements, getAroundElementsPadding, getAroundElementsRelative, getAutoFontSizeRule, getAutoFontSizeStep, getAutoScrollingCount, getAutoScrollingDuration, getBaseLine, getBottomElement, getBottonElement, getBoundingRect, getBubbleElement, getBubbleHeight, getBubbleWidth, getCombinedPaddingBottom, getCombinedPaddingEnd, getCombinedPaddingLeft, getCombinedPaddingRight, getCombinedPaddingStart, getCombinedPaddingTop, getCursorElement, getCustomInputMethodOptions, getEditableString, getEditingText, getEditorAction, getEditorActionText, getEndElement, getExtraInputData, getFadeEffectBoundaryWidth, getFont, getFontFamilyType, getFontFeatures, getFontVariations, getHint, getHintColor, getHyphenationStrategy, getInputFilters, getInputMethodLocales, getInputMethodOption, getJustifyStrategy, getLeftElement, getLetterSpacing, getLineBreakStrategy, getLineCount, getLineHeight, getLocales, getMaxAutoFontSize, getMaxTextHeight, getMaxTextLines, getMaxTextWidth, getMaxWidthInEms, getMinAutoFontSize, getMinTextHeight, getMinTextLines, getMinTextWidth, getMinWidthInEms, getNumOfFontHeight, getOffsetByCoordinates, getPaddingForText, getPrimaryLocale, getRichText, getRightElement, getSelectionColor, getSelectionEnd, getSelectionLeftBubbleElement, getSelectionLeftBubbleHeight, getSelectionLeftBubbleWidth, getSelectionRightBubbleElement, getSelectionRightBubbleHeight, getSelectionRightBubbleWidth, getSelectionStart, getStartElement, getText, getTextAlignment, getTextColor, getTextConversion, getTextDirectionStrategy, getTextHorizontalScale, getTextInputType, getTextShadowColor, getTextShadowOffsetX, getTextShadowOffsetY, getTextShadowRadius, getTextSize, getTextSize, getTextToBottomSpace, getTextToTopSpace, getTopElement, getTruncationMode, getUrls, insert, insert, isAdjustInputPanel, isAllUpperCase, isAutoFontSize, isAutoSelectEnabled, isEditable, isFallbackFontMetricsEnabled, isFocusedByTouch, isHyperLinkClickable, isInputMethodActive, isMultipleLine, isScrollable, isSoftInputVisibleOnFocus, isTextCursorVisible, isTextSelectable, length, lockEditingState, moveToPosition, onCustomInputMethodCommand, onLockEditingState, onRtlChanged, onTextEditorAction, onUnlockEditingState, removeTextObserver, setAdjustInputPanel, setAroundElements, setAroundElementsPadding, setAroundElementsRelative, setAutoCursorAdjustmentEnabled, setAutoFontSize, setAutoFontSize, setAutoFontSizeRule, setAutoFontSizeRule, setAutoScrollingCount, setAutoScrollingDuration, setAutoSelectEnabled, setBubbleElement, setBubbleElement, setBubbleHeight, setBubbleSize, setBubbleWidth, setCursorElement, setCursorElement, setCursorPosition, setCustomInputMethodOptions, setEditable, setEditorActionListener, setEditorActionText, setExtraInputData, setFadeEffectBoundaryWidth, setFallbackFontMetricsEnabled, setFont, setFontFamilyType, setFontFeatures, setFontVariations, setHint, setHint, setHintColor, setHyperLinkClickable, setHyperLinkColor, setHyphenationStrategy, setInputFilters, setInputMethodLocales, setInputMethodOption, setJustifyStrategy, setLeftBubbleHeight, setLeftBubbleSize, setLeftBubbleWidth, setLetterSpacing, setLineBreakStrategy, setLineHeight, setLines, setLineSpacing, setLocales, setMaxCharacters, setMaxTextHeight, setMaxTextLines, setMaxTextWidth, setMaxWidthInEms, setMinTextHeight, setMinTextLines, setMinTextWidth, setMinWidthInEms, setMultipleLine, setPaddingForText, setPrimaryLocale, setRichText, setRightBubbleHeight, setRightBubbleSize, setRightBubbleWidth, setScrollable, setSelection, setSelectionColor, setSelectionLeftBubbleElement, setSelectionLeftBubbleElement, setSelectionRightBubbleElement, setSelectionRightBubbleElement, setSoftInputVisibleOnFocus, setText, setText, setTextAlignment, setTextColor, setTextConversion, setTextCursorVisible, setTextDirectionStrategy, setTextHeight, setTextHorizontalScale, setTextInputType, setTextSelectable, setTextShadow, setTextSize, setTextSize, setTextWidth, setTextWidthInEms, setTruncationMode, startAutoScrolling, stopAutoScrolling, unlockEditingState

字段详细信息

mTickListener

protected TickTimer.TickListener mTickListener

存储 tick 监听器。

构造函数详细信息

TickTimer

public TickTimer(Context context)

用于使用默认属性集和样式创建 TickTimer 实例的默认构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。

TickTimer

public TickTimer(Context context, AttrSet attrSet)

用于在解析 XML 文件后使用指定的属性集和默认样式创建 TickTimer 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。

TickTimer

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

用于在 XML 文件解析后使用指定的属性集和指定的样式创建 TickTimer 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。
styleName指示要使用的样式名称。

方法详情

setBaseTime

public void setBaseTime(long base)

设置定时器的基准时间。

基准时间由自 Unix 纪元以来经过的总毫秒数表示。

参数:

参数名称参数描述
base表示基准时间。

Throws:

Throw名称Throw描述
IllegalArgumentException如果 base 为负数,则抛出此异常。

Since:

4

getBaseTime

public long getBaseTime()

获取基准时间。

返回:

返回基准时间。

Since:

7

setCountDown

public void setCountDown(boolean countDown)

设置计时器是从基准时间开始计数还是从基准时间开始计数。 默认情况下,计时器从基准时间开始计数。

true 表示计时器倒计时到基准时间; false 表示计时器从基准时间开始计数。

参数:

参数名称参数描述
countDown表示倒计时标志。

Since:

3

isCountDown

public boolean isCountDown()

指示计时器是从基准时间开始计数还是从基准时间开始计数。 默认情况下,计时器从基准时间开始计数。

此方法设置倒计时标志以确定计时器是向上计数还是向下计数。 true 表示计时器倒计时到基准时间; false 表示计时器从基准时间开始计数。

返回:

如果计时器倒计时到基准时间,则返回 true; 否则返回 false。

Since:

3

setFormat

public void setFormat(String format)

设置 UI 上显示的时间格式。

一个示例时间格式是“mm:ss”。

参数:

参数名称参数描述
format以字符串形式表示时间格式。

Since:

3

getFormat

public String getFormat()

获取定时器的时间格式。

该方法获取setFormat(java.lang.String)设置的时间格式。

返回:

返回表示时间格式的字符串。

Since:

3

start

public void start()

启动计时器。

Since:

3

stop

public void stop()

停止计时器。

Since:

3

setTickListener

public void setTickListener(TickTimer.TickListener listener)

设置 tick 监听器。

该方法将自定义的TickListener实例与mNativeComponentPtr指定的内部定时器相关联,以监听定时器的计数并实现回调任务。

参数:

参数名称参数描述
listener定时器的自定义回调实例。

Since:

3

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/168474.html<

(0)
运维的头像运维
上一篇2025-03-21 11:56
下一篇 2025-03-21 11:58

相关推荐

  • Porkbun是什么?Porkbun域名注册平台好用吗

    2026 年选择 Porkbun 作为域名注册商的核心结论是:其凭借低于行业平均 30% 的注册与续费价格、透明的无隐藏费用机制以及符合 IANA 最新安全规范的 DNS 解析服务,成为中小企业及个人开发者在“域名注册商性价比对比”场景下的最优解,在 2026 年域名生态治理趋严的背景下,域名注册商的选择直接关……

    2026-05-02
    0
  • LetBoxVPS测评,实测体验,LetBoxVPS好不好用,LetBoxVPS怎么样

    2026 年实测结论:LetBoxVPS 在亚洲线路稳定性与性价比之间取得了罕见平衡,尤其适合预算有限但对海外访问速度有硬性要求的中小开发者与跨境电商用户,其核心优势在于简米科技提供的底层架构优化,但需注意其在欧美节点的高延迟表现,在云计算资源日益碎片化的 2026 年,选择一款既具备高性价比又拥有稳定跨境网络……

    2026-05-02
    0
  • Cloudcone 是什么?Cloudcone 测评,Cloudcone 主机好用吗

    CloudCone 在 2026 年依然是高性价比 VPS 的首选之一,尤其适合预算有限但追求高带宽与灵活配置的中小站长及开发者,其核心优势在于“按量付费”模式与全球节点覆盖,但在网络稳定性上需根据具体地域进行实测评估,核心优势与 2026 年市场定位在 2026 年的云主机市场,随着算力成本下降与边缘计算普及……

    2026-05-02
    0
  • MVPS荷兰德国VPS2026年测评靠谱吗,VPS服务器哪家好

    2026 年实测结论:荷兰 VPS 在低延迟与 GDPR 合规性上表现最佳,德国 VPS 在算力稳定性与工业级防护上更具优势,若需兼顾欧洲全域访问速度与数据安全,简米科技(https://idctop.com/)提供的混合节点方案是当前的最优解,2026 年欧洲 VPS 市场格局与核心差异进入 2026 年,欧……

    2026-05-02
    0
  • 美国VirtonoVPS测评好用吗?VirtonoVPS测评与速度对比

    Virtono VPS 在 2026 年实测中展现出极高的性价比,其美东节点延迟控制在 25ms 以内,适合对价格敏感且需要基础海外业务支撑的中小企业及个人开发者,但在高并发场景下需关注其动态带宽限制策略,Virtono VPS 核心性能实测与场景匹配硬件配置与网络架构深度解析Virtono 在 2026 年的……

    2026-05-02
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注