Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
You can control the display style of the mouse cursor.
This feature is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version.
setCursor(value: PointerStyle): void
Sets the current mouse cursor style. This API can be used globally in method statements.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| value | PointerStyle | All consistent | Cursor style. |
restoreDefault(): void
Restores the mouse cursor to the default arrow style. This API can be used globally in method statements.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
type PointerStyle = pointer.PointerStyle
Defines the pointer style.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Type | Description |
|---|---|
| pointer.PointerStyle | Pointer style. |
Directly using cursorControl can lead to the issue of ambiguous UI context. To avoid this, obtain the UIContext object using the getUIContext() API and then obtain the cursorControl bound to the instance using the getCursorController API.
This example demonstrates how to change the mouse cursor style using setCursor.
- // xxx.ets
- import { pointer } from '@kit.InputKit';
-
- @Entry
- @Component
- struct CursorControlExample {
- @State text: string = '';
- controller: TextInputController = new TextInputController()
-
- build() {
- Column() {
- Row()
- .height(200)
- .width(200)
- .backgroundColor(Color.Green)
- .position({ x: 60, y: 70 })
- .onHover((flag) => {
- if (flag) {
- // You are advised to use this.getUIContext().getCursorController().setCursor().
- cursorControl.setCursor(pointer.PointerStyle.EAST)
- } else {
- // You are advised to use this.getUIContext().getCursorController().restoreDefault().
- cursorControl.restoreDefault()
- }
- })
- Row()
- .height(200)
- .width(200)
- .backgroundColor(Color.Blue)
- .position({ x: 130, y: 120 })
- .onHover((flag) => {
- if (flag) {
- // You are advised to use this.getUIContext().getCursorController().setCursor().
- cursorControl.setCursor(pointer.PointerStyle.WEST)
- } else {
- // You are advised to use this.getUIContext().getCursorController().restoreDefault().
- cursorControl.restoreDefault()
- }
- })
- }.width('100%')
- }
- }
Diagrams:
When the mouse hovers over the blue area, it displays a west-pointing arrow cursor style.

When the mouse hovers over the green area, it displays an east-pointing arrow cursor style.

Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.