目录

Creating a Service Widget

Overview

Service widgets present important information about apps/atomic services, allowing users to access desired features instantly via shortcut gestures.

Widgets are classified as static widgets and dynamic widgets. Static widgets occupy less memory, which helps optimize overall device memory. They support static information display, refresh, and tap-to-navigate features. Dynamic widgets support custom interactions, animations, and scrolling, offering rich functionality but consuming more memory.

From the perspective of build products, widget packages are classified into shared packages and standalone packages. For details, see Creating an ArkTS Widget.

Creation Mode

Widget Type

Shared package

Static widget

Dynamic widget

Standalone package

Static standalone widget

Dynamic standalone widget

After creating a widget, you can select different widget templates based on service requirements. The following table lists the widget templates and their descriptions.

Template

Supported Device Type

Programming Language

Description

Hello World

Phones, tablets, 2-in-1 devices, wearables, cars, and TVs

ArkTS, JS

This template implements a HelloWorld service widget for building the UI efficiently and intuitively. It can be in 6 x 4 dimensions.

Image With Information

Phones, tablets, 2-in-1 devices, wearables, and cars

ArkTS, JS

This template is used to display images and a certain amount of text in equal importance. The image size and text amount vary depending on the widget size to highlight key information.

Immersive Information

Phones, tablets, 2-in-1 devices, wearables, and cars

ArkTS, JS

This template delivers a touch of aesthetics and quality with a properly designed layout of information and background images, helping to create an immersive user experience.

List

Phones, tablets, 2-in-1 devices, and cars

ArkTS

This template provides basic list functionality. Currently, it is only available for dynamic service widgets using API version 11 or later.

Control Button

Phones, tablets, 2-in-1 devices, and cars

ArkTS

This template implements an actionable service widget that displays text information and buttons, with button clicks triggering events. Currently, it is only available for static service widgets using API version 11 or later.

Control Search

Phones, tablets, 2-in-1 devices, and cars

ArkTS

This template implements an actionable service widget applicable to search scenarios. Currently, it is only available for static service widgets using API version 11 or later.

Constraints

Creating a Service Widget

After creating a project, you can create a widget as follows.

  1. Use either of the following methods:

    • Select a file under a module (for example, an entry module), choose File > New > Service Widget on the menu bar, and select a widget as required.
    • Right-click a file under a module (for example, an entry module), choose New > Service Widget from the shortcut menu, and select a widget as required.
    • In the stage model of API version 11 or later, no widget or EntryCard is created for a new atomic service project or a new model in an atomic service project by default.

  2. On the Choose a Template for Your Service Widget page, select a template and click Next.

  3. On the Configure Your Service Widget page, set the following:

    • Service widget name: service widget name, which must be unique in an app/atomic service and can contain only uppercase letters, lowercase letters, digits, and underscores (_).
    • Display name: service widget name displayed on the preview canvas. This field is only available for projects in the stage model of API version 11 or later.
    • Description: description of the service widget.
    • Language: programming language of the service widget, which can be ArkTS or JS.
    • Support dimensions: dimensions of the service widget. Certain types of service widgets allow for multiple dimensions options. When a widget is created for the first time, an EntryCard folder is automatically generated for storing widget snapshots.
    • Default dimension: default dimension of the service widget.
    • Ability name: Form ability bound to the widget. You can select an existing one or create a new one.
    • Module name: module to which the service widget belongs.

  4. When you have finished, click Finish. After the service widget is created, the tool automatically generates the layout file and writes the attributes of the service widget into the form_config.json file. For details about the attributes, see Configuring ArkTS Widget Configuration Files.
  5. Develop the service widget based on instructions in ArkTS Widget Provider Development.

Previewing a Service Widget

During widget development, you can preview them to ensure their functionality and appearance. The layout of a widget is designed in an ArkTS file. Once you have saved the layout file, you will be able to see layout changes in real time on the preview canvas. Widgets of phones and tablets can be previewed in three scenarios: Minimum, Default, and Maximum. Make sure your widget displays properly in all these scenarios.

For details about the preview features, see Previewing the UI.