目录

Creating an ArkTS Widget

You can create an ArkTS widget package in either of the following ways:

Method 1: Create a shared package. For details, see Creating a Shared Package. The widget UI and application code are in the same module, and the final compilation product is in the same HAP.

Method 2: Create a standalone package. For details, see Creating a Standalone Package. The widget UI and application code are in different modules, and the final compilation products are in separate widget and application packages. The initial APIs of this module are supported since API version 20.

After an ArkTS widget is created, you can preview the widget in real time during development. For details, see Previewing a Service Widget.

Method 1: Creating a Shared Package

[h2]Procedure

1. Create a project.

In DevEco Studio, create an application or atomic service project. Both types of projects support widget creation. For details about how to create a project, see Creating a Project.

The UI may be different in DevEco Studio of a different version.

2. Create a widget.

In an existing application project, right-click to create an ArkTS widget. The procedure is as follows:

[h2]Project Structure

Figure 1 ArkTS widget project directory and related modules

Method 2: Creating a Standalone Package

[h2]Procedure

1. Create a project.

In DevEco Studio, create an application or atomic service project. Both types of projects support widget creation. For details about how to create a project, see Creating a Project.

The UI may be different in DevEco Studio of a different version.

2. Create a widget.

[h2]Project Structure

If a widget is created using a standalone widget package or a shared widget package, the project structure is different but the generated files are the same. For details about the files, see Project Structure in a Shared Package.

Figure 2 Project directory of a standalone widget package

The application package and widget package in a standalone widget package are two independent modules. Therefore, you need to ensure that the application package and widget package installed at the same time have the same version number.