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
Window appearance describes the display form and visual effect of a window on the screen. Currently, you can set the window appearance by configuring shaped windows, window shadows, window rounded corners, as well as the window background color.
You can customize the window appearance based on UI design and interaction requirements. For example:
Display a subwindow or global floating window as a shaped window by setting the window mask.
Adjust the shadow effect of a subwindow or global floating window by setting the blur radius of the window edge shadow.
Adjust the edge display effect of a subwindow or global floating window by setting window rounded corners.
Make the window background consistent with the app page or theme style by setting the window background color.
A shaped window is a window with a non-rectangular shape, and a mask is used to describe the shape of the shaped window. Only app subwindows and global floating windows can be set as shaped windows.
You can set the mask of a shaped window through the setWindowMask() or setWindowMaskWithAlpha() API to define the visible region of the window.
After setting the mask, the window will be displayed according to the mask shape, the window shadow will be disabled, and the corner radius of the window will become 0.
Use the setWindowMask() API to set the mask for a shaped window.
The mask only supports a two-dimensional array input with integer values of 0 and 1. The number of rows in the array corresponds to the window height, and the number of columns corresponds to the window width. 0 indicates that the corresponding pixel is transparent and non-interactive, while 1 indicates that the corresponding pixel is opaque and interactive.

Starting from API version 26.0.0, the setWindowMaskWithAlpha() API is supported for setting the mask of a shaped window.
The mask supports array input with values in the range [0, 255], where the array length equals the window width multiplied by the window height. An integer value of 0 indicates that the corresponding pixel is transparent and non-interactive, 255 indicates that the corresponding pixel is opaque and interactive, and values between 0 and 255 indicate that the corresponding pixel is partially transparent and interactive. This API offers better performance than setWindowMask() and is recommended.

The following takes setting a shaped window for a subwindow as an example.
Tap Create Sub Window to create a subwindow.
After the subwindow is created, tap setWindowMask for Sub Window to set the subwindow mask using the setWindowMaskWithAlpha() API. The subwindow undergoes the following changes:
The subwindow becomes a triangle.
The shadow and rounded corners of the subwindow disappear.
The upper-left part of the subwindow's rectangular area becomes transparent and non-interactive. Tapping the Create Test Window button allows the event to pass through to that button, creating a green test window.
- import { window } from '@kit.ArkUI';
- import { BusinessError } from '@kit.BasicServicesKit';
-
- @Entry
- @Component
- struct Index {
- // ...
- private windowMaskSub: window.Window | undefined = undefined;
-
- // ...
- setWindowMask(window: window.Window) {
- let windowMask: Uint8Array = new Uint8Array(this.winWidth * this.winHeight);
- for (let i = 0; i < this.winHeight; i++) {
- for (let k = 0; k < this.winWidth; k++) {
- if ((i + k) < (this.winHeight + this.winWidth) / 2) {
- windowMask[i * this.winWidth + k] = 0;
- } else {
- windowMask[i * this.winWidth + k] = 255;
- }
- }
- }
- window.setWindowMaskWithAlpha(windowMask, this.winWidth, this.winHeight);
- }
-
- build() {
- Row() {
- Scroll(){
- Column() {
- // ...
- Row() {
- Button('setWindowMask for Sub Window')
- .width('90%')
- .type(ButtonType.Capsule)
- .margin({
- top: 10
- }).fontSize(18)
- .onClick(() => {
- if(this.windowMaskSub) {
- this.setWindowMask(this.windowMaskSub);
- }
- })
- }
- }
- .width('100%')
- }
- }
- .height('100%')
- }
-
- }

A window shadow is a projection effect displayed at the window edge, which enhances the sense of depth between the window and the background, creating a visual effect of the window floating above the background.
You can use the setWindowShadowRadius() API to set the blur radius of the window edge shadow. This is only supported for subwindows and global floating windows.
Here, a global floating window is used as an example to set the blur radius of its window shadow.
- // pages/page1.ets
- import { window } from '@kit.ArkUI';
-
- @Entry
- @Component
- struct SliderDemo {
- // ...
-
- // Set the blur radius of the window edge shadow.
- setShadowRadius(val: number) {
- const floatWindowObj = AppStorage.get<window.Window>('floatWindow');
- floatWindowObj?.setWindowShadowRadius(val);
- }
-
- build() {
- // ...
- }
- }

You can use the setWindowCornerRadius() API to set the corner radius of a window. This is only supported for subwindows and global floating windows.
Here, a global floating window is used as an example to set its window corner radius.
- // pages/page1.ets
- import { window } from '@kit.ArkUI';
-
- @Entry
- @Component
- struct SliderDemo {
- // ...
-
- // Set the corner radius.
- setCornerRadius(val: number) {
- const floatWindowObj = AppStorage.get<window.Window>('floatWindow');
- floatWindowObj?.setWindowCornerRadius(val);
- }
-
- build() {
- // ...
- }
- }

The window background color is used to control the background display effect of the window content area or the window container area.
You can choose to set the background color of the app content area or the window container area including the title bar based on business scenarios, to achieve effects such as transparent page backgrounds and unified overall window color schemes.
You can use the setWindowBackgroundColor() API to adjust the background color of the window content area, which primarily affects the part of the window that carries UI content. You can pass a case-insensitive hexadecimal RGB or ARGB color to adjust the background color. Starting from API version 18, the ColorMetrics type is supported.
You can use the setWindowContainerColor() API to set the background color of the main window container area on PCs, 2-in-1 devcies, or tablets. The window container background color covers the entire window area, including the title bar and content area. If not in the freeform window state, the effect is equivalent to setWindowBackgroundColor(). This API does not support setting the main window background to transparent when it is not in focus.
When both setWindowContainerColor() and setWindowBackgroundColor() are used, the content area displays the color set by setWindowBackgroundColor(), while the title bar displays the color set by setWindowContainerColor().
Starting from API version 26.0.0, the setWindowContainerModalColor() interface is supported for setting the background color of the main window container area on PCs or 2-in-1 devices to accommodate different UI design requirements. The background color set through this API applies to the entire window container area, including the title bar and content area. This API supports setting the main window background to transparent when it is not in focus.
When the setWindowContainerColor() or setWindowContainerModalColor() API is not called to set the window container area background color, the container area background color defaults to following the system color mode: '#FFF0F0F0' in light mode and '#FF1A1A1A' in dark mode.
The background color can only be set after loadContent() or setUIContent() takes effect.

The sample code is as follows:
- import { ColorMetrics, window } from '@kit.ArkUI';
- import { hilog } from '@kit.PerformanceAnalysisKit';
-
- const DOMAIN = 0x0000;
-
- @Entry
- @Component
- struct Index {
- @StorageLink('mainWindow') mainWindow: window.Window | undefined = undefined;
-
- @State alpha: number = 0;
- @State red: number = 0;
- @State green: number = 0;
- @State blue: number = 0;
- @State statusText: string = 'Move the sliders to change the current window background color.';
- @State applyModeText: string = 'Current mode: string (#AARRGGBB)';
-
- aboutToAppear(): void {
- this.applyWindowBackgroundColor();
- }
-
- // Convert channel values from 0 to 255 into two-digit hexadecimal strings for concatenating #AARRGGBB.
- private toHex(value: number): string {
- return Math.round(value).toString(16).padStart(2, '0').toUpperCase();
- }
-
- // Generate a hexadecimal string of the current window background color in ARGB order.
- private getColorValue(): string {
- return `#${this.toHex(this.alpha)}${this.toHex(this.red)}${this.toHex(this.green)}${this.toHex(this.blue)}`;
- }
- // ...
- // Set the window background color directly using ColorMetrics.rgba(...).
- private applyByColorMetrics(): void {
- if (!this.mainWindow) {
- this.statusText = 'Current window is unavailable.';
- return;
- }
-
- try {
- const alpha = Math.round(this.alpha) / 255;
- const colorMetrics = ColorMetrics.rgba(Math.round(this.red), Math.round(this.green),
- Math.round(this.blue), alpha);
- this.mainWindow.setWindowBackgroundColor(colorMetrics);
- this.applyModeText = 'Current mode: ColorMetrics.rgba(...)';
- this.statusText = `setWindowBackgroundColor(ColorMetrics.rgba(${Math.round(this.red)}, ${Math.round(this.green)}, ${Math.round(this.blue)}, ${alpha.toFixed(2)})) success`;
- hilog.info(DOMAIN, 'backgroundColor', this.statusText);
- } catch (err) {
- this.statusText = `setWindowBackgroundColor by ColorMetrics failed: ${JSON.stringify(err)}`;
- hilog.error(DOMAIN, 'backgroundColor', this.statusText);
- }
- }
-
- // ...
- }
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.