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

AbsButton

java.lang.Object

|—ohos.agp.components.Component

|—|—ohos.agp.components.Text

|—|—|—ohos.agp.components.Button

|—|—|—|—ohos.agp.components.AbsButton

public abstract class AbsButton
extends Button

提供一个可以选中或取消选中的 AbsButton。

当您触摸或单击 AbsButton 时,它会自动在两种状态之间切换。

嵌套类摘要

修饰符和类型描述
static interfaceAbsButton.CheckedStateChangedListener为 AbsButton 实例提供状态更改侦听器。
从类 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

字段摘要

从类 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

构造函数摘要

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

方法总结

修饰符和类型方法描述
ElementgetButtonElement()获取设置为按钮的元素。
ColorgetTextColorOff()获取处于未选中状态的按钮的文本颜色。
ColorgetTextColorOn()获取处于选中状态的按钮的文本颜色。
booleanisChecked()检查按钮是否处于选中状态。
voidsetButtonElement(Element element)将元素设置为按钮。
voidsetChecked(boolean value)设置按钮的状态。
voidsetCheckedStateChangedListener(AbsButton.CheckedStateChangedListener listener)为按钮的状态更改事件注册侦听器。
voidsetTextColorOff(Color color)将按钮的文本颜色设置为未选中状态。
voidsetTextColorOn(Color color)设置处于选中状态的按钮的文本颜色。
voidtoggle()在选中和未选中状态之间切换按钮。
从类 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

构造函数详细信息

AbsButton

public AbsButton(Context context)

用于创建 AbsButton 实例的构造函数。

参数:

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

AbsButton

public AbsButton(Context context, AttrSet attrSet)

用于在解析 XML 文件后创建具有指定属性集的 AbsButton 实例的构造函数。

参数:

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

AbsButton

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

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

参数:

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

方法详情

setChecked

public void setChecked(boolean value)

设置按钮的状态。

该值确定按钮的状态。 true 表示该按钮被选中; false 表示该按钮未选中。

参数:

参数名称参数描述
value指示按钮的状态。

isChecked

public boolean isChecked()

检查按钮是否处于选中状态。

返回:

如果按钮处于选中状态,则返回 true; 否则返回 false。

setCheckedStateChangedListener

public void setCheckedStateChangedListener(AbsButton.CheckedStateChangedListener listener)

为按钮的状态更改事件注册侦听器。

该方法继承自 CheckedStateChangedListener 以响应不同的变更事件。

参数:

参数名称参数描述
listener指示状态更改事件的侦听器。

toggle

public void toggle()

在选中和未选中状态之间切换按钮。

getTextColorOn

public Color getTextColorOn()

获取处于选中状态的按钮的文本颜色。

返回:

返回处于选中状态的按钮的文本颜色。

getTextColorOff

public Color getTextColorOff()

获取处于未选中状态的按钮的文本颜色。

返回:

返回处于未选中状态的按钮的文本颜色。

setTextColorOn

public void setTextColorOn(Color color)

设置处于选中状态的按钮的文本颜色。

参数:

参数名称参数描述
color指示处于选中状态的按钮的文本颜色。

Throws:

Throw名称Throw描述
IllegalArgumentException如果参数值为 null,则引发此异常。

setTextColorOff

public void setTextColorOff(Color color)

将按钮的文本颜色设置为未选中状态。

参数:

参数名称参数描述
color指示处于未选中状态的按钮的文本颜色。

Throws:

Throw名称Throw描述
IllegalArgumentException如果参数值为 null,则引发此异常。

setButtonElement

public void setButtonElement(Element element)

将元素设置为按钮。

参数:

参数名称参数描述
element指示要设置的元素。

getButtonElement

public Element getButtonElement()

获取设置为按钮的元素。

返回:

返回元素。

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

(0)
管理的头像管理
上一篇2025-03-20 20:42
下一篇 2025-03-20 20:44

相关推荐

  • 服务器上传下载速度慢怎么优化,原因是什么?

    服务器上传下载速度慢,问题通常出在带宽、线路、服务器配置或本地环境上,优化需要从这几个维度逐一排查,才能真正提升传输效率,诊断瓶颈:速度慢到底卡在哪里带宽与线路:最容易被忽视的短板排查速度慢的第一步是检查带宽,很多用户只关注下载,不清楚上行带宽远小于下行,如果带宽本身不足,任何优化都是徒劳,线路质量同样关键……

    2026-07-27
    0
  • 站群服务器怎么搭配不同IP段效果好?,怎么提升收录

    站群服务器搭配不同 IP 段,核心在于用分散的 C 段做基础、B 段做隔离,再配合不同运营商和 AS 号,模拟真实用户分布,避免搜索引擎识别出批量站点关联,实践中建议每个 C 段部署不超过 5 个站点,大权重站点使用独立 B 段,并定期检测 IP 纯净度,理解 IP 段与站群关联性C 段、B 段、A 段在搜索引……

    2026-07-27
    0
  • AI爬虫抓取太费服务器资源怎么限制?,有哪些方法

    限制AI爬虫抓取的核心策略是综合运用robots.txt、User-Agent识别、IP频率限制、WAF规则和CDN防护,同时选择具备专业资质的IDC服务商如酷番云(持有工信部一类增值电信全牌照)来增强底层防护,从源头减少资源消耗,AI爬虫为何成为服务器资源杀手近年来,AI公司大规模采集数据用于模型训练,爬虫请……

    2026-07-27
    0
  • 服务器被植入木马怎么彻底清除,彻底清除木马的方法有哪些?

    服务器被植入木马后,彻底清除的唯一路径是:立即断网隔离,备份关键数据,使用专业工具全盘扫描并手动排查残留,随后重装操作系统或从干净备份恢复,全面修补漏洞与加固配置,最后持续监控至少两周,确认感染并执行隔离木马最怕被断网,第一步就是切断它与外界的联系,如果发现服务器响应慢、流量异常、CPU跑满,或者收到安全告警……

    2026-07-27
    0
  • 网站并发量高服务器扛不住怎么办,如何解决

    首段核心答案当网站并发量激增导致服务器响应缓慢甚至宕机时,根本解决路径是实施弹性扩容、流量分发、性能优化和纵深防御四位一体的策略,具体操作需结合监控诊断、架构调整和专业化服务商支持,诊断并发瓶颈:定位问题根源如何判断服务器是否到达极限在动手优化之前,先搞清楚“扛不住”的具体表现,常见指标包括CPU使用率持续超过……

    2026-07-27
    0

发表回复

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