The Slider component is used to quickly adjust settings, such as the volume and brightness. It supports style customization, direction configuration, interaction modes, and accessibility, which helps resolve UI consistency issues and improve development efficiency, thereby enhancing user experience and reducing development costs.
This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Since API version 26.0.0, when material parameters are passed to the Slider component, the preset visual parameters inside the component are used. The passed material parameters serve only as a switch flag for enabling the system material and do not affect the actual visual effect. They mainly affect the visual attributes of the Slider component, such as the slider size, slider style, and shadow. When undefined is passed, the system material does not take effect, and the original slider style is displayed.
Slider(options?: SliderOptions)
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| options | SliderOptions | No | Parameters of the slider. |
Provides information about the slider.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| value | number | No | Yes | Current progress. Default value: same as the value of min. Since API version 10, this attribute supports two-way binding through $$. This attribute supports two-way binding through !!. Value range: [min, max] If the value is less than the value of min, the value of min is used; if the value is greater than the value of max, the value of max is used. The $$ operator provides a reference to a TS variable for a system component, keeping the value of the TS variable synchronized with value of the Slider component. For details, see Example 7: Setting Two-Way Binding for the Slider. |
| min | number | No | Yes | Minimum value. Default value: 0 |
| max | number | No | Yes | Maximum value. Default value: 100 Note: If the value of min is greater than or equal to the value of max, the min value defaults to 0, and the max value defaults to 100. If the value is not within the [min, max] range, the value of min or max is used, whichever is closer. |
| step | number | No | Yes | Step of the slider. Default value: 1 Value range: [0.01, max - min] Note: If this parameter is set to a value less than 0 or greater than max - min, the default value is used. |
| style | SliderStyle | No | Yes | Style of the slider thumb and track. Default value: SliderStyle.OutSet |
| direction8+ | Axis | No | Yes | Whether the slider moves horizontally or vertically. Default value: Axis.Horizontal |
| reverse8+ | boolean | No | Yes | Whether the slider values are reversed. true: A horizontal slider slides from right to left, and a vertical slider slides from bottom to top. false: A horizontal slider slides from left to right, and a vertical slider slides from top to bottom. Default value: false |
Enumerates the display styles of the slider thumb relative to the track. For details, see How Are the Slider Thumb and Track of the Slider Component Aligned?.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| OutSet | 0 | The thumb is on the track. Widget capability: This API can be used in ArkTS widgets since API version 9. Atomic service API: This API can be used in atomic services since API version 11. |
| InSet | 1 | The thumb is in the track. Widget capability: This API can be used in ArkTS widgets since API version 9. Atomic service API: This API can be used in atomic services since API version 11. |
| NONE12+ | 2 | There is no thumb. Widget capability: This API can be used in ArkTS widgets since API version 12. Atomic service API: This API can be used in atomic services since API version 12. Model restriction: This API can be used only in the stage model. |
blockColor(value: ResourceColor)
Sets the color of the thumb.
When SliderBlockType.DEFAULT is used, blockColor sets the color of the round thumb.
When SliderBlockType.IMAGE is used, blockColor does not work as the thumb has no fill color.
When SliderBlockType.SHAPE is used, blockColor sets the color of the thumb in a custom shape.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | Yes | Color of the thumb. Default value: $r('sys.color.ohos_id_color_foreground_contrary') |
blockColor(value: ResourceColor | LinearGradient)
Sets the color of the slider. Gradient colors are supported. Compared with blockColor, it supports the LinearGradient type.
When SliderBlockType.DEFAULT is used, blockColor sets the color of the round thumb.
When SliderBlockType.IMAGE is used, blockColor does not work as the thumb has no fill color.
When SliderBlockType.SHAPE is used, blockColor sets the color of the thumb in a custom shape.
Widget capability: This API can be used in ArkTS widgets since API version 21.
Atomic service API: This API can be used in atomic services since API version 21.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | LinearGradient | Yes | Slider color. Default value: $r('sys.color.ohos_id_color_foreground_contrary') Note: When the slider shape is set to SliderBlockType.IMAGE, the slider has no fill, and setting blockColor does not take effect. |
trackColor(value: ResourceColor | LinearGradient)
Sets the background color of the track.
Since API version 12, the LinearGradient type can be used to set the gradient color of the track.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API supports only the ResourceColor type in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | LinearGradient | Yes | Background color of the track. Default value: $r('sys.color.ohos_id_color_component_normal') Note: 1. When a gradient color is set, if the color value of a color stop is invalid or the gradient color stop is empty, the gradient color does not take effect. 2. The LinearGradient type in this API is not supported in atomic services. |
trackColorMetrics(color: ColorMetricsLinearGradient)
Sets the linear gradient background color of the track. Compared with trackColor, it uses the ColorMetricsLinearGradient type to support gradients in a specified color gamut.
Atomic service API: This API can be used in atomic services since API version 23.
Relationship with trackColor: trackColorMetrics is similar to trackColor in functionality, but uses the ColorMetricsLinearGradient type to support gradient control in a specified color gamut. The LinearGradient type in trackColor is not supported in atomic services, whereas trackColorMetrics is. The two are similar in functionality and cannot take effect at the same time. The API called later overrides the setting of the API called earlier.
System capability: SystemCapability.ArkUI.ArkUI.Full
Model restriction: This API can be used only in the stage model.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| color | ColorMetricsLinearGradient | Yes | Linear gradient background color of the track. When a gradient color is set, if the value of color is undefined, the gradient color setting does not take effect, and the default background color of the track is $r('sys.color.ohos_id_color_component_normal'). |
selectedColor(value: ResourceColor)
Sets the color of the portion of the track between the minimum value and the thumb, representing the selected portion.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | Yes | Color of the portion of the track between the minimum value and the thumb. Default value: $r('sys.color.ohos_id_color_emphasize') |
selectedColor(selectedColor: ResourceColor | LinearGradient)
Sets the color of the portion of the track between the minimum value and the thumb, representing the selected portion. Compared to selectedColor, this API supports the LinearGradient type.
Widget capability: This API can be used in ArkTS widgets since API version 18.
Atomic service API: This API can be used in atomic services since API version 18.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| selectedColor | ResourceColor | LinearGradient | Yes | Color of the portion of the track between the minimum value and the thumb. Default value: $r('sys.color.ohos_id_color_emphasize') NOTE With gradient color settings, if the color stop values are invalid or if the color stops are empty, the gradient effect will not be applied. |
showSteps(value: boolean)
Sets whether to display the step markers.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | boolean | Yes | Whether to display the step markers. true: display the step markers; false: do not display the step markers. Default value: false |
showTips(value: boolean, content?: ResourceStr)
Sets whether to display a tooltip when the user drags the slider.
When direction is set to Axis.Horizontal, the tooltip is displayed above the block. If the space above is insufficient to display the complete tooltip, it is displayed below. When direction is set to Axis.Vertical, the tooltip is displayed to the left of the slider. If the space on the left is insufficient to display the complete tooltip, it is displayed on the right. When no surrounding margin is set, or the margin is smaller than the space required by the tooltip, the tooltip is truncated.
The drawing area of the tooltip is the overlay of the slider.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | boolean | Yes | Whether to display a tooltip when the user drags the slider. true: Display a tooltip. false: Do not display a tooltip. Default value: false |
| content10+ | ResourceStr | No | Text content of the tooltip. When passed in, custom text is displayed (used when a specific format or additional information needs to be shown); when not passed in, the current percentage value is displayed by default. Model restriction: This API can be used only in the stage model. |
trackThickness(value: Length)
Sets the thickness of the track. If the value is less than or equal to 0, the default value is used.
To ensure SliderStyle works as expected for the thumb and track, blockSize should increase or decrease proportionally with trackThickness.
When style is set to SliderStyle.OutSet, trackThickness:blockSize=1:4. When style is set to SliderStyle.InSet, trackThickness:blockSize=5:3.
If the value of trackThickness or blockSize exceeds the width or height of the Slider component, the default value is used.
When SliderStyle is set to OutSet, if the specified value of blockSize exceeds the width or height of the Slider component, the default value is used, regardless of whether the value of trackThickness is valid or not.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | Length | Yes | Thickness of the track. Default value: 4.0vp when style is set to SliderStyle.OutSet, and 20.0vp when style is set to SliderStyle.InSet. |
blockBorderColor(value: ResourceColor)
Sets the border color of the slider in the block direction.
When SliderBlockType.DEFAULT is used, blockBorderColor sets the border color of the round slider.
When SliderBlockType.IMAGE is used, blockBorderColor does not work as the slider has no border.
When SliderBlockType.SHAPE is used, blockBorderColor sets the border color of the slider in a custom shape.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | Yes | Border color of the slider in the block direction. Default value: '#00000000' |
blockBorderWidth(value: Length)
Sets the border width of the slider in the block direction.
When SliderBlockType.DEFAULT is used, blockBorderWidth sets the border width of the round slider.
When SliderBlockType.IMAGE is used, blockBorderWidth does not work as the slider has no border.
When SliderBlockType.SHAPE is used, blockBorderWidth sets the border width of the slider in a custom shape.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | Length | Yes | Border width of the slider. Note: For the string type, percentage values are not supported. |
stepColor(value: ResourceColor)
Sets the step color.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | ResourceColor | Yes | Step color. Default value: The $r('sys.color.ohos_id_color_foreground') color mixed with the transparency of $r('sys.color.ohos_id_alpha_normal_bg'). |
trackBorderRadius(value: Length)
Sets the radius of the rounded corner of the track.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | Length | Yes | Radius of the rounded corner of the track. Default value: The default value is 2vp when style is set to SliderStyle.OutSet. The default value is 10vp when style is set to SliderStyle.InSet. Note: If the value is less than 0, the default value is used. |
selectedBorderRadius(value: Dimension)
Set the corner radius of the selected (highlighted) part of the slider.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | Dimension | Yes | Corner radius of the selected part of the slider. Default value: When style is set to SliderStyle.InSet or SliderStyle.OutSet, the default value follows the corner radius of the track; when style is set to SliderStyle.NONE, the default value is 0. Note: Percentage values are not supported. If the value is less than 0, the default value is used. |
blockSize(value: SizeOptions)
Sets the size of the slider in the block direction.
When the slider type is set to SliderBlockType.DEFAULT, the smaller of the width and height values is used as the radius of the circle.
When the slider type is set to SliderBlockType.IMAGE, this API sets the size of the image, which is scaled using the ObjectFit.Cover strategy.
When the slider type is set to SliderBlockType.SHAPE, this API sets the size of the custom shape, which is also scaled using the ObjectFit.Cover strategy.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | SizeOptions | Yes | Slider size. Default value: When the value of the style parameter is set to SliderStyle.OutSet, the default value is {width: 18, height: 18}; when the value of the style parameter is set to SliderStyle.InSet, the default value is {width: 12, height: 12}; when the value of the style parameter is set to SliderStyle.NONE, this parameter does not take effect. If the set blockSize has different width and height values, the smaller value is taken. If one or both of the width and height values are less than or equal to 0, the default value is used instead. |
blockStyle(value: SliderBlockStyle)
Sets the style of the slider in the block direction.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | SliderBlockStyle | Yes | Slider style. The default value is SliderBlockType.DEFAULT, indicating a circular slider. |
stepSize(value: Length)
Sets the step size (diameter). If the value is 0, the step size is not displayed. If the value is less than 0, the default value is used.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | Length | Yes | Step size (diameter). Default value: '4vp' Value range: [0, trackThickness), in vp |
sliderInteractionMode(value: SliderInteraction)
Sets the interaction mode between the user and the slider.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | SliderInteraction | Yes | Interaction mode between the user and the slider. Default value: SliderInteraction.SLIDE_AND_CLICK. |
minResponsiveDistance(value: number)
Sets the minimum response distance for the slider to start sliding.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | number | Yes | Minimum response distance for the slider to start sliding. Default value: 0 Note: The unit is the same as that of the min and max attributes in SliderOptions. If the value is less than 0, greater than max – min, NaN, or of a non-numeric type, the default value is used. |
contentModifier(modifier: ContentModifier<SliderConfiguration>)
Creates a content modifier.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| modifier | ContentModifier<SliderConfiguration> | Yes | Content modifier to apply to the Slider component. ContentModifier: content modifier. You need a custom class to implement the ContentModifier API. |
slideRange(value: SlideRange)
Sets the valid sliding range. After this attribute is set, the sliding range of the slider is limited to [from, to]. Taps and gestures outside this range do not trigger sliding. If the initial value of value exceeds the range, it is automatically adjusted to the boundary of the range.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | SlideRange | Yes | Valid sliding range. |
enableHapticFeedback(enabled: boolean)
Specifies whether to enable haptic feedback.
To enable haptic feedback, you must declare the ohos.permission.VIBRATE permission under requestPermissions in the module.json5 file of the project.
"requestPermissions": [
{
"name": "ohos.permission.VIBRATE"
}
] Atomic service API: This API can be used in atomic services since API version 18.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| enabled | boolean | Yes | Whether to enable haptic feedback. true: enable haptic feedback; false: disable haptic feedback. Default value: true |
digitalCrownSensitivity(sensitivity: Optional<CrownSensitivity>)
Sets the sensitivity to the digital crown rotation.
Atomic service API: This API can be used in atomic services since API version 18.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| sensitivity | Optional<CrownSensitivity> | Yes | Sensitivity to the digital crown rotation. Default value: CrownSensitivity.MEDIUM |
prefix(content: ComponentContent, options?: SliderPrefixOptions)
Sets the prefix of the slider.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| content | ComponentContent | Yes | Visual content of the slider prefix, which will be displayed at the start of the slider. |
| options | SliderPrefixOptions | No | Configuration options of the slider prefix, used to set accessibility-related attributes. Default value: null |
suffix(content: ComponentContent, options?: SliderSuffixOptions)
Sets the suffix of the slider.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| content | ComponentContent | Yes | Visual content of the slider suffix, which will be displayed at the end position of the slider. |
| options | SliderSuffixOptions | No | Configuration options of the slider suffix, used to set accessibility-related attributes. Default value: null |
showSteps(value: boolean, options?: SliderShowStepOptions)
Sets whether to display the step markers along the slider track.
You can set custom accessibility text for each step value. If no accessibility text is provided, the numeric values are used.
The accessibility text settings take effect only when the step markers are displayed.
Widget capability: This API can be used in ArkTS widgets since API version 20.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | boolean | Yes | Whether to display the step markers. true: display the step markers; false: do not display the step markers. Default value: false |
| options | SliderShowStepOptions | No | Configuration options of the accessibility text of the step markers. Default value: null |
minLabel(value: string)
Sets the text content of the minimum value label.
This API is supported since API version 7 and deprecated since API version 9. You are advised to use the min attribute in SliderOptions instead.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | string | Yes | Text of the minimum value label. |
maxLabel(value: string)
Sets the text content of the maximum value label.
This API is supported since API version 7 and deprecated since API version 9. You are advised to use the max attribute of SliderOptions instead.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | string | Yes | Text of the maximum value label. |
constructor(colorStops: ColorMetricsStop[])
Constructor of ColorMetricsLinearGradient.
Atomic service API: This API can be used in atomic services since API version 23.
System capability: SystemCapability.ArkUI.ArkUI.Full
Model restriction: This API can be used only in the stage model.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| colorStops | ColorMetricsStop[] | Yes | Array of color stops for the linear gradient. Each element describes a color and its stop value in the gradient. |
Describes the linear gradient color stop type.
Atomic service API: This API can be used in atomic services since API version 23.
System capability: SystemCapability.ArkUI.ArkUI.Full
Model restriction: This API can be used only in the stage model.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| color | ColorMetrics | No | No | Color value of the linear gradient color stop. |
| offset | Length | No | No | Value of the linear gradient color stop. The value is a proportion ranging from 0 to 1. If a value less than 0 is passed, the value is set to 0. If a value greater than 1 is passed, the value is set to 1. Note: If the value is a string that represents a number, it will be converted to a number. For example, '10vp' is converted to 10, and '10%' is converted to 0.1. |
Provides accessibility configuration of the slider prefix and suffix.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| accessibilityText | ResourceStr | No | Yes | Accessibility text for screen readers and other tools to read, enhancing accessibility. Default value: "" |
| accessibilityDescription | ResourceStr | No | Yes | Accessibility details, which describe the functionality or purpose of the slider prefix or suffix, for screen readers and other tools to use. Default value: "Double-tap to activate" |
| accessibilityLevel | string | No | Yes | Whether the component can be recognized by the accessibility service. The options are as follows: "auto": It is treated as "yes" by the system. "yes": The component can be recognized by the accessibility service. "no": The component cannot be recognized by the accessibility service. "no-hide-descendants": The component and all its child components cannot be recognized by the accessibility service. Default value: "auto". |
| accessibilityGroup | boolean | No | Yes | Whether the element belongs to an accessibility group, helping screen readers and other tools group related elements. true: The component and all its child components form a single selectable unit, and the accessibility service no longer focus on the content of its child components. false: accessibility grouping is not enabled. Default value: false |
Provides accessibility configuration of the slider prefix.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Inherits from SliderCustomContentOptions.
Provides accessibility configuration of the slider suffix.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Inherits from SliderCustomContentOptions.
Provides accessibility configuration of the slider step markers.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| text | ResourceStr | No | Yes | Accessibility text for screen readers and other tools to read, enhancing accessibility. Default value: "" |
Provides accessibility text mapping for the slider step markers.
Atomic service API: This API can be used in atomic services since API version 20.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| stepsAccessibility | Map<number, SliderStepItemAccessibility> | No | Yes | Accessibility text mapping for the slider step markers, read by tools such as screen readers to enhance accessibility. Key value range: [0, INT32_MAX]. When the key is set to a negative number or a decimal, the setting does not take effect. Default value: {} |
Describes the style of the slider in the block direction.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| type | SliderBlockType | No | No | Type of the slider. Default value: SliderBlockType.DEFAULT, indicating a circular slider. |
| image | ResourceStr | No | Yes | Image resource of the slider. The size of the image display area is controlled by the blockSize attribute. Do not use an oversized image. Note: This attribute takes effect only when type is set to SliderBlockType.IMAGE, and is mutually exclusive with the shape attribute. They cannot be used together. |
| shape | Circle | Ellipse | Path | Rect | No | Yes | Custom shape of the block. Note: This attribute takes effect only when type is set to SliderBlockType.SHAPE, and is mutually exclusive with the image attribute. They cannot be used together. |
Enumerates the types of the slider in the block direction.
Atomic service API: This API can be used in atomic services since API version 11.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| DEFAULT | 0 | Round slider. |
| IMAGE | 1 | Slider with an image background. |
| SHAPE | 2 | Slider in a custom shape. |
Interaction mode between the user and the slider.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| SLIDE_AND_CLICK | 0 | Users can drag the slider or touch the track to move the slider. The slider moves as soon as the mouse or finger is pressed. |
| SLIDE_ONLY | 1 | Users are not allowed to move the slider by touching the slider. |
| SLIDE_AND_CLICK_UP | 2 | Users can drag the slider or touch the track to move the slider. The slider moves when the mouse is released or finger is lifted, if the release/lift position coincides with the screen press position. |
Defines the valid sliding range.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| from | number | No | Yes | Start of the slide range. |
| to | number | No | Yes | End of the slide range. |
onChange(callback: (value: number, mode: SliderChangeMode) => void)
Triggered when the slider is dragged or clicked.
The Begin and End states are triggered on a tap, and the Moving and Click states are triggered when the value changes.
A continuous drag action does not trigger the Click state.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | number | Yes | Current sliding progress. The precision of the return value is determined by the step parameter of Slider. If the return value contains decimals, use number.toFixed() to process the data to the expected precision. |
| mode | SliderChangeMode | Yes | State triggered by the event. The value options include Begin, Moving, End, and Click. For details, see SliderChangeMode. |
Enumerates the slider states, including pressed, dragged, released, and moved when the slider is tapped.
Widget capability: This API can be used in ArkTS widgets since API version 9.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| Begin | 0 | The user touches or clicks the thumb. |
| Moving | 1 | The user is dragging the slider. |
| End | 2 | The user releases the slider by a gesture or mouse. Note: This state is triggered when the user releases the slider by a gesture or mouse, including the end of a normal drag. It is also triggered when an invalid value is restored to the default value, that is, when the value is set to a value less than min or greater than max. |
| Click8+ | 3 | The user moves the thumb by clicking the track. |
You need a custom class to implement the ContentModifier API. Inherits from CommonConfiguration.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| value | number | No | No | Current progress. |
| min | number | No | No | Minimum value. |
| max | number | No | No | Maximum value. |
| step | number | No | No | Step of the slider, which indicates the value increment of each slider movement. |
| triggerChange | SliderTriggerChangeCallback | No | No | Triggers slider changes. |
type SliderTriggerChangeCallback = (value: number, mode: SliderChangeMode) => void
Defines the callback type used in SliderConfiguration.
Atomic service API: This API can be used in atomic services since API version 12.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | number | Yes | Current progress. |
| mode | SliderChangeMode | Yes | State triggered by the event. |
This example demonstrates how to control the display of the tooltip, current step, and slider thumb and track by configuring style, showTips, and showSteps.
// xxx.ets
@Entry
@Component
struct SliderExample {
@State outSetValueOne: number = 40;
@State inSetValueOne: number = 40;
@State noneValueOne: number = 40;
@State outSetValueTwo: number = 40;
@State inSetValueTwo: number = 40;
@State vOutSetValueOne: number = 40;
@State vInSetValueOne: number = 40;
@State vOutSetValueTwo: number = 40;
@State vInSetValueTwo: number = 40;
build() {
Column({ space: 8 }) {
Text('outset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: this.outSetValueOne,
min: 0,
max: 100,
style: SliderStyle.OutSet
})
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.outSetValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
// toFixed(0) converts the return value of the slider to an integer.
Text(this.outSetValueOne.toFixed(0)).fontSize(12)
}
.width('80%')
Row() {
Slider({
value: this.outSetValueTwo,
step: 10,
style: SliderStyle.OutSet
})
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.outSetValueTwo = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Text(this.outSetValueTwo.toFixed(0)).fontSize(12)
}
.width('80%')
Text('inset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: this.inSetValueOne,
min: 0,
max: 100,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.inSetValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Text(this.inSetValueOne.toFixed(0)).fontSize(12)
}
.width('80%')
Row() {
Slider({
value: this.inSetValueTwo,
step: 10,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.inSetValueTwo = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Text(this.inSetValueTwo.toFixed(0)).fontSize(12)
}
.width('80%')
Text('none slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: this.noneValueOne,
min: 0,
max: 100,
style: SliderStyle.NONE
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.noneValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Text(this.noneValueOne.toFixed(0)).fontSize(12)
}
.width('80%')
Row() {
Column() {
Text('vertical outset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)
Row() {
Text().width('10%')
Slider({
value: this.vOutSetValueOne,
style: SliderStyle.OutSet,
direction: Axis.Vertical
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vOutSetValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Slider({
value: this.vOutSetValueTwo,
step: 10,
style: SliderStyle.OutSet,
direction: Axis.Vertical
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vOutSetValueTwo = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
}
}.width('50%').height(300)
Column() {
Text('vertical inset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)
Row() {
Slider({
value: this.vInSetValueOne,
style: SliderStyle.InSet,
direction: Axis.Vertical,
reverse: true // For a vertical slider, the top end is the min value and the bottom end is the max value by default. To slide from bottom to top, set reverse to true.
})
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vInSetValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
Slider({
value: this.vInSetValueTwo,
step: 10,
style: SliderStyle.InSet,
direction: Axis.Vertical,
reverse: true
})
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.vInSetValueTwo = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
}
}.width('50%').height(300)
}
}.width('100%')
}
} 
This example demonstrates how to customize the slider styles by setting blockBorderColor, blockSize, blockBorderWidth, and blockStyle for the slider block, stepSize and stepColor for the step, trackBorderRadius for the track's corner radius, and selectedBorderRadius for the selected part's corner radius.
@Entry
@Component
struct SliderExample {
@State tipsValue: number = 40;
build() {
Column({ space: 8 }) {
Text('block').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.OutSet, value: 40 })
.blockSize({ width: 40, height: 40 })
.blockBorderColor(Color.Red)
.blockBorderWidth(5)
Divider()
Text('step').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.InSet, value: 40, step: 10 })
.showSteps(true)
.stepSize(8)
.stepColor(Color.Yellow)
Divider()
Text('track').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.InSet, value: 40 })
.trackBorderRadius(2)
Divider()
Text('selected').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.InSet, value: 40 })
.selectedBorderRadius(2)
Divider()
Text('blockStyle').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.OutSet, value: 40 })
.blockStyle({ type: SliderBlockType.DEFAULT })
Slider({ style: SliderStyle.OutSet, value: 40 })
.blockStyle({ type: SliderBlockType.IMAGE, image: $r('sys.media.ohos_app_icon') })
Slider({ style: SliderStyle.OutSet, value: 40 })
.blockSize({ width: '60px', height: '60px' })
.blockColor(Color.Red)
.blockStyle({ type: SliderBlockType.SHAPE, shape: new Path({ commands: 'M60 60 M30 30 L15 56 L45 56 Z' }) })
Divider()
Text('tips').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
Slider({ style: SliderStyle.InSet, value: this.tipsValue })
.showTips(true, this.tipsValue.toFixed())
.onChange(value => {
this.tipsValue = value;
})
}
}
} 
This example demonstrates how to customize the Slider component using a style builder to define the content area. Clicking the increase button will increment the progress bar by the step size set in the original Slider component, and clicking the decrease button will decrement the progress bar, triggering the onChange event of the original component.
// xxx.ets
@Builder
function buildSlider(config: SliderConfiguration) {
Row() {
Column({ space: 30 }) {
Progress({ value: config.value, total: config.max, type: ProgressType.Ring })
.margin({ top: 20 })
Button('Increase')
.onClick(() => {
config.value = config.value + config.step;
config.triggerChange(config.value, SliderChangeMode.Click);
})
.width(100)
.height(25)
.fontSize(10)
.enabled(config.value < config.max)
Button('Decrease')
.onClick(() => {
config.value = config.value - config.step;
config.triggerChange(config.value, SliderChangeMode.Click);
})
.width(100)
.height(25)
.fontSize(10)
.enabled(config.value > config.min)
Slider({
value: config.value,
min: config.min,
max: config.max,
step: config.step,
})
.width(100)
.visibility((config.contentModifier as MySliderStyle).showSlider ? Visibility.Visible : Visibility.Hidden)
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
config.triggerChange(value, mode);
})
Text('Current state: ' + ((config.contentModifier as MySliderStyle).sliderChangeMode == 0 ? "Begin"
: ((config.contentModifier as MySliderStyle).sliderChangeMode == 1 ? "Moving"
: ((config.contentModifier as MySliderStyle).sliderChangeMode == 2 ? "End"
: ((config.contentModifier as MySliderStyle).sliderChangeMode == 3 ? "Click" : "None")))))
.fontSize(10)
Text('Progress: ' + config.value)
.fontSize(10)
Text('Min: ' + config.min)
.fontSize(10)
Text('Max: ' + config.max)
.fontSize(10)
Text('Step: ' + config.step)
.fontSize(10)
}
.width('80%')
}
.width('100%')
}
class MySliderStyle implements ContentModifier<SliderConfiguration> {
showSlider: boolean = true;
sliderChangeMode: number = 0;
constructor(showSlider: boolean, sliderChangeMode: number) {
this.showSlider = showSlider;
this.sliderChangeMode = sliderChangeMode;
}
applyContent(): WrappedBuilder<[SliderConfiguration]> {
return wrapBuilder(buildSlider);
}
}
@Entry
@Component
struct SliderExample {
@State showSlider: boolean = true;
@State sliderValue: number = 0;
@State sliderMin: number = 10;
@State sliderMax: number = 100;
@State sliderStep: number = 20;
@State sliderChangeMode: number = 0;
build() {
Column({ space: 8 }) {
Row() {
Slider({
value: this.sliderValue,
min: this.sliderMin,
max: this.sliderMax,
step: this.sliderStep,
})
.showSteps(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.sliderValue = value;
this.sliderChangeMode = mode;
console.info('SliderLog value:' + value + 'mode:' + mode.toString());
})
.contentModifier(new MySliderStyle(this.showSlider, this.sliderChangeMode))
}
.width('100%')
}.width('100%')
}
} 
This example demonstrates how to set a color gradient effect to the slider using selectedColor and implement support for digital crown interactions through focusable, defaultFocus, and focusOnTouch.
// xxx.ets
@Entry
@Component
struct SliderExample {
@State inSetValueOne: number = 60
@State colorGradient: LinearGradient = new LinearGradient([{ color: "#FF0000FF", offset: 0 }, { color: "#FFFF0000", offset: 1 }])
@State sensitivity: CrownSensitivity | undefined | null = CrownSensitivity.MEDIUM
scroller: Scroller = new Scroller()
getIntegerDigits(num: number): string {
let numRound = Math.round(num);
return numRound.toString();
}
build() {
Column() {
Scroll(this.scroller){
Column() {
Row() {
Stack({ alignContent: Alignment.Top }) {
Slider({
value: this.inSetValueOne,
min: 0,
max: 100,
style: SliderStyle.NONE,
direction: Axis.Vertical,
reverse: true
})
.focusable(true)
.defaultFocus(true)
.focusOnTouch(true)
.digitalCrownSensitivity(this.sensitivity)
.trackColor("#26FFFFFF")
.trackThickness(52)
.selectedColor(this.colorGradient)
.onChange((value: number, mode: SliderChangeMode) => {
this.inSetValueOne = value
})
}
.height(233 - 66)
.width(52)
.margin({ top: 33, bottom: 33, left: 56 })
Column() {
Text('Volume')
.fontSize(19)
.fontColor("#A9FFFFFF")
.fontWeight(500)
.textAlign(TextAlign.Start)
.margin({ left: 20 })
Row() {
Text(this.getIntegerDigits(this.inSetValueOne))
.fontSize(52)
.fontColor("#FFFFFFFF")
.fontWeight(700)
.textAlign(TextAlign.Start)
.margin({ left: 20 })
Text('%')
.fontSize(19)
.fontColor("#FFFFFFFF")
.fontWeight(500)
.textAlign(TextAlign.Start)
.margin({ left: 2 })
}
}.alignItems(HorizontalAlign.Start)
}
.width(233)
.height(233)
.borderRadius(116.5)
.backgroundColor(Color.Black)
}
}
}.width('100%')
}
} 
This example demonstrates how to set the prefix and suffix of the slider using prefix and suffix, defining their custom content and accessibility configuration. After the accessibility configuration is specified, the screen reader announces the accessibility text accordingly.
// xxx.ets
import { ComponentContent } from '@kit.ArkUI';
class NodeParams {
param: ResourceStr = ""
constructor(param: ResourceStr) {
this.param = param;
}
}
@Builder
function textBuilder(params: NodeParams) {
Text(params.param)
.fontSize($r('sys.float.Caption_L'))
.clip(true)
.textAlign(TextAlign.Center)
.fontColor(Color.Black)
}
@Entry
@Component
struct SliderExample {
private pre: string = 'Low';
private suf: string = 'High';
private uiContext: UIContext = this.getUIContext();
private preNode1: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode1: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
private preNode2: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode2: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
private preNode3: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode3: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
private preNode4: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode4: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
private preNode5: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode5: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
private preNode6: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.pre));
private sufNode6: ComponentContent<NodeParams> = new ComponentContent(this.uiContext, wrapBuilder(textBuilder), new NodeParams(this.suf));
build() {
Column({ space: 8 }) {
Text('outset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.OutSet
})
.showTips(true)
.prefix(this.preNode1)
.suffix(this.sufNode1)
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.OutSet
})
.showTips(true)
.prefix(this.preNode3)
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.OutSet
})
.showTips(true)
.suffix(this.sufNode3)
}
.width('80%')
Text('inset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.prefix(this.preNode2)
.suffix(this.sufNode2)
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.prefix(this.preNode4)
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.suffix(this.sufNode4)
}
.width('80%')
Text('slider Show Step').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
Row() {
Slider({
value: 50,
min: 0,
max: 100,
step:10,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.showSteps(true)
.prefix(this.preNode5, {
accessibilityText: 'prefixText',
accessibilityDescription: 'prefixDescription',
accessibilityLevel: 'auto',
accessibilityGroup: true
})
.suffix(this.sufNode5, {
accessibilityText: 'suffixText',
accessibilityDescription: 'suffixDescription',
accessibilityLevel: 'auto',
accessibilityGroup: true
})
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
step:10,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.showSteps(true)
.prefix(this.preNode6, {
accessibilityText: 'prefixText',
accessibilityDescription: 'prefixDescription',
accessibilityLevel: 'auto',
accessibilityGroup: true
})
}
.width('80%')
Row() {
Slider({
value: 50,
min: 0,
max: 100,
step:10,
style: SliderStyle.InSet
})
.blockColor('#191970')
.trackColor('#ADD8E6')
.selectedColor('#4169E1')
.showTips(true)
.trackThickness(36)
.showSteps(true)
.suffix(this.sufNode6, {
accessibilityText: 'suffixText',
accessibilityDescription: 'suffixDescription',
accessibilityLevel: 'auto',
accessibilityGroup: true
})
}
.width('80%')
}.width('100%')
}
} 
This example demonstrates how to set accessibility text for step markers using showSteps. The screen reader announces the set accessibility text accordingly. The options parameter is added for the showSteps attribute since API version 20.
class SliderBlockBorderColorModifier1 implements AttributeModifier<SliderAttribute>{
optionMaps:Map<number, SliderStepItemAccessibility> = new Map()
.set(1, {text : '123123'})
.set(2, {text : 'Slider accessibility text'})
.set(3, {text : $r('app.string.stepItemText')})
.set(4, {text : '!@#$%^&*()'});
applyNormalAttribute(instance: SliderAttribute): void {
instance.showSteps(true, {stepsAccessibility: this.optionMaps})
}
}
@Entry
@Component
struct SliderExample {
@State show: boolean = true;
@State optionMaps:Map<number, SliderStepItemAccessibility> = new Map();
private sliderModifier: SliderBlockBorderColorModifier1 =new SliderBlockBorderColorModifier1()
aboutToAppear(){
this.optionMaps.set(1, {text : '123123'})
this.optionMaps.set(2, {text : 'Slider accessibility text'})
this.optionMaps.set(3, {text : $r('app.string.app_name')})
this.optionMaps.set(4, {text : '!@#$%^&*()'})
this.show = true;
}
build() {
Column({ space: 8 }) {
Text('This is an example for showSteps attribute').fontSize(15).fontColor(0x000000).margin(15).width('90%')
Row() {
Slider({
style: SliderStyle.InSet,
value: 20,
step: 10,
max: 50,
min: 0,
direction: Axis.Horizontal
})
.stepSize(8)
.stepColor(Color.Yellow)
.showSteps(true, {stepsAccessibility: this.optionMaps})
}.width('80%').height(100)
Divider()
Text('This is an example for showSteps attribute with modifier').fontSize(15).fontColor(0x000000).margin(15)
.width('90%')
Row() {
Slider({
style: SliderStyle.InSet,
value: 20,
step: 10,
max: 50,
min: 0,
direction: Axis.Horizontal
})
.stepSize(8)
.stepColor(Color.Yellow)
.attributeModifier(this.sliderModifier)
}.width('80%').height(100)
Divider()
}
}
} 
This example shows how to implement data synchronization by binding the value property of SliderOptions to a variable using the $$ two-way binding operator, available since API version 11.
// xxx.ets
@Entry
@Component
struct SliderExample {
@State valueWith$: number = 40
@State valueWithout$: number = 40
build() {
Column({ space: 20 }) {
Text("Using $$ two-way binding: " + this.valueWith$)
Slider({
value: $$this.valueWith$,
min: 0,
max: 100,
})
Text("Without $$ two-way binding: " + this.valueWithout$)
Slider({
value: this.valueWithout$,
min: 0,
max: 100,
})
}
}
} 
This example demonstrates how to set a gradient color for the Slider component's thumb using the blockColor attribute.
@Entry
@Component
struct SliderExample {
@State colorGradient: LinearGradient = new LinearGradient([{ color: "#FFFFFF", offset: 0 }, { color: "#007DFF", offset: 1 }])
build() {
Column({ space: 10 }) {
Slider({
style:SliderStyle.OutSet,
min: 0,
max: 100,
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.OutSet,
min: 0,
max: 100,
reverse: true
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.InSet,
min: 0,
max: 100,
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.InSet,
min: 0,
max: 100,
reverse: true
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.NONE,
min: 0,
max: 100,
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.NONE,
min: 0,
max: 100,
reverse: true
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Row({ space: 20 }){
Slider({
style:SliderStyle.OutSet,
min: 0,
max: 100,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.OutSet,
min: 0,
max: 100,
reverse: true,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.InSet,
min: 0,
max: 100,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.InSet,
min: 0,
max: 100,
reverse: true,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.NONE,
min: 0,
max: 100,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
Slider({
style:SliderStyle.NONE,
min: 0,
max: 100,
reverse: true,
direction:Axis.Vertical
})
.blockColor(this.colorGradient)
.blockSize({width:"50vp",height:"50vp"})
}.height("50%")
}.width("100%")
}
} 
This example demonstrates how to set the gradient color stop of the specified color gamut using trackColorMetrics. In this example, colorSpace is of the ColorSpace.DISPLAY_P3 type. You need to call the setWindowColorSpace API of the corresponding window to set the current window to the wide color gamut mode. For details, see setWindowColorSpace.
The trackColorMetrics API is supported since API version 23.
// xxx.ets
import { ColorMetrics } from '@kit.ArkUI';
@Entry
@Component
struct SliderExample {
@State greenColor: ColorMetrics = ColorMetrics.colorWithSpace(ColorSpace.DISPLAY_P3, 0.0, 1.0, 0.0, 1);
@State yellowColor: ColorMetrics = ColorMetrics.colorWithSpace(ColorSpace.DISPLAY_P3, 1.0, 1.0, 0.0, 1);
@State inSetValueOne: number = 40;
@State color: ColorMetricsLinearGradient =
new ColorMetricsLinearGradient([{ color: this.greenColor, offset: 0 }, { color: this.yellowColor, offset: 1 }])
build() {
Column({ space: 8 }) {
Slider({
value: this.inSetValueOne,
min: 0,
max: 100,
style: SliderStyle.InSet
}).margin('10')
.width('80%')
.blockColor('#FF0000')
.trackColorMetrics(this.color)
.selectedColor('#4169E1')
.showTips(true)
.onChange((value: number, mode: SliderChangeMode) => {
this.inSetValueOne = value;
console.info('value:' + value + 'mode:' + mode.toString());
})
}.alignItems(HorizontalAlign.Center)
.width('100%')
}
} 
This example shows how to set the system material of the slider using the universal attribute systemMaterial, implementing the immersive light effect. After the system material is set, a particle animation effect is generated during the sliding of the slider.
The illustration in this example shows the strong effect on a high-computing-power device. The immersive light effect of the component is adaptively adjusted based on the device computing power and the immersive light effect set by the user in the system, and you do not need to perform additional adaptation.
The systemMaterial API is supported since API version 26.0.0.
// xxx.ets
import { uiMaterial } from '@kit.ArkUI';
@Entry
@Component
struct SliderSystemMaterial {
build() {
RelativeContainer() {
Slider({
style: SliderStyle.InSet
})
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center },
})
.systemMaterial(new uiMaterial.ImmersiveMaterial({
style: uiMaterial.ImmersiveStyle.ULTRA_THIN,
}))
}
.height('100%')
.width('100%')
// Replace it with the actual resource file.
.backgroundImage($r("app.media.img"))
}
} System material not set

System material set
