• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 图形图像开发常见问题
2
3## 调用window实例的setSystemBarProperties接口时,设置isStatusBarLightIcon和isNavigationBarLightIcon属性不生效
4
5适用于:OpenHarmony SDK 3.2.5.3版本,API9 Stage模型
6
7状态栏字体高亮属性的本质就只是让字体变成白色。调用window实例的setSystemBarProperties接口时,如果设置了状态栏内容颜色statusBarContentColor,就以开发者设置的颜色为准,isStatusBarLightIcon状态栏字体高亮属性就不生效;同理,如果设置了导航栏内容颜色navigationBarContentColor,isNavigationBarLightIcon导航栏字体高亮属性就不生效。
8
9## 如何设置系统状态栏样式
10
11适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
12
13导入\@ohos.window模块,开发者可以使用window.setSystemBarProperties()接口设置状态栏样式属性,达到自定义样式的效果。
14
15## 如何隐藏状态栏,实现沉浸式效果
16
17适用于:OpenHarmony SDK 3.2.6.3版本,API9 Stage模型
18
191. 可以在onWindowStageCreate方法获取windowClass对象。
20
21   ```
22   onWindowStageCreate(windowStage) {
23     // Main window is created, set main page for this ability
24     console.log("[Demo] MainAbility onWindowStageCreate")
25     windowStage.getMainWindow((err, data) => {
26       if (err.code) {
27         console.error('Failed to obtain the main window.')
28         return;
29       }
30       // 获取到窗口对象
31       globalThis.windowClass = data;
32     })
33   }
34   ```
35
362. 设置窗口全屏,隐藏状态栏。
37
38   ```
39    globalThis.windowClass.setFullScreen(isFullScreen, (err, data) => {
40     if (err.code) {
41       console.error('Failed to enable the full-screen mode. Cause:' + JSON.stringify(err));
42       return;
43     }
44       console.info('Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data));
45     });
46   ```
47
48## 如何获取窗口的宽高信息
49
50适用于:OpenHarmony SDK 3.2.3.5版本,API9 Stage模型
51
52通过\@ohos.window模块,可以使用getProperties()接口获取窗口属性,然后通过窗口属性的windowRect获取窗口宽高信息
53
54示例:
55
56
57```
58let promise = windowClass.getProperties();
59promise.then((data)=> {
60  console.info('Succeeded in obtaining the window properties. Data: ' + JSON.stringify(data.windowRect));
61}).catch((err)=>{
62  console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(err));
63});
64```
65
66## 如何设置系统状态栏颜色
67
68适用于:OpenHarmony SDK 3.2.5.5版本,API9 Stage模型
69
70参考如下方式实现,示例:
71
72
73```
74window.getTopWindow(globalThis.mainContext).then(win => {
75  var systemBarProperties = {
76    statusBarColor: '#19B6FF', // 状态栏背景颜色
77    navigationBarColor: '#19B6FF', // 导航栏背景颜色
78    isStatusBarLightIcon: false, // 状态栏图标是否为高亮状态。
79    isNavigationBarLightIcon: true, // 导航栏图标是否为高亮状态。
80    statusBarContentColor: '#0D0500', // 状态栏文字颜色
81    navigationBarContentColor: '#FFA500' // 导航栏文字颜色
82  };
83  win.setSystemBarProperties(systemBarProperties).catch(err => {
84    INDEX_LOGGER.info(`set System Bar Properties failed:${err}`)
85  })
86})
87.catch(err => {
88  INDEX_LOGGER.info(`get top window failed:${err}`)
89})
90```
91