1# Interface (AtomicServiceBar) 2<!--Kit: ArkUI--> 3<!--Subsystem: ArkUI--> 4<!--Owner: @jiangtao92--> 5<!--Designer: @piggyguy--> 6<!--Tester: @songyanhong--> 7<!--Adviser: @HelloCrease--> 8 9提供设置原子化服务menuBar的属性。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 14> 15> - 本Interface首批接口从API version 11开始支持。 16> 17> - 以下接口需要先使用UIContext中的[getAtomicServiceBar](arkts-apis-uicontext-uicontext.md#getatomicservicebar11)方法获取到AtomicServiceBar对象,再通过该对象调用对应方法。 18> 19> - 从API version 12开始原子化服务menuBar样式变更,以下接口将失效。 20 21## setVisible<sup>11+</sup> 22 23setVisible(visible: boolean): void 24 25通过该方法设置原子化服务menuBar是否可见。 26> **说明:** 27> 28> 从API version 12开始原子化服务menuBar样式变更,menuBar默认隐藏,变为悬浮按钮,通过该接口无法改变menuBar的可见性。 29 30**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 31 32**系统能力:** SystemCapability.ArkUI.ArkUI.Full 33 34**参数:** 35 36| 参数名 | 类型 | 必填 | 说明 | 37| ------- | ------- | ------- | ------- | 38| visible | boolean | 是 | 原子化服务menuBar是否可见。true表示设置menuBar可见,false表示设置menuBar不可见。| 39 40 41**示例:** 42 43```ts 44import { UIAbility } from '@kit.AbilityKit'; 45import { UIContext, AtomicServiceBar, window } from '@kit.ArkUI'; 46import { hilog } from '@kit.PerformanceAnalysisKit'; 47 48export default class EntryAbility extends UIAbility { 49 onWindowStageCreate(windowStage: window.WindowStage) { 50 // Main window is created, set main page for this ability 51 hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate'); 52 windowStage.loadContent('pages/Index', (err, data) => { 53 let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); 54 let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 55 if (atomicServiceBar != undefined) { 56 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.'); 57 atomicServiceBar.setVisible(false); 58 } else { 59 hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.'); 60 } 61 }); 62 } 63} 64``` 65 66## setBackgroundColor<sup>11+</sup> 67 68setBackgroundColor(color:Nullable<Color | number | string>): void 69 70通过该方法设置原子化服务menuBar的背景颜色。 71> **说明:** 72> 73> 从API version 12开始原子化服务menuBar样式变更,menuBar的背景默认隐藏,通过该接口无法改变menuBar的背景颜色。 74 75**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 76 77**系统能力:** SystemCapability.ArkUI.ArkUI.Full 78 79**参数:** 80 81| 参数名 | 类型 | 必填 | 说明 | 82| ------ | ------ | ------ | ------ | 83| color | Nullable\<[Color](arkui-ts/ts-appendix-enums.md#color) \| number \| string> | 是 | 通过该方法设置原子化服务menuBar的背景颜色,undefined代表使用默认颜色。number为HEX格式颜色,支持rgb或者argb,示例:0xffffff。string为rgb或者argb格式颜色,示例:'#ffffff'。| 84 85**示例:** 86 87```ts 88import { UIAbility } from '@kit.AbilityKit'; 89import { UIContext, AtomicServiceBar, window } from '@kit.ArkUI'; 90import { hilog } from '@kit.PerformanceAnalysisKit'; 91 92export default class EntryAbility extends UIAbility { 93 onWindowStageCreate(windowStage: window.WindowStage) { 94 // Main window is created, set main page for this ability 95 hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate'); 96 windowStage.loadContent('pages/Index', (err, data) => { 97 let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); 98 let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 99 if (atomicServiceBar != undefined) { 100 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.'); 101 atomicServiceBar.setBackgroundColor(0x88888888); 102 } else { 103 hilog.error(0x0000, 'testTag', 'Get AtomicServiceBar failed.'); 104 } 105 }); 106 } 107} 108``` 109 110## setTitleContent<sup>11+</sup> 111 112setTitleContent(content:string): void 113 114通过该方法设置原子化服务menuBar的标题内容。 115> **说明:** 116> 117> 从API version 12开始原子化服务menuBar样式变更,menuBar的标题默认隐藏,通过该接口无法改变menuBar的标题内容。 118 119**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 120 121**系统能力:** SystemCapability.ArkUI.ArkUI.Full 122 123**参数:** 124 125|参数名|类型|必填|说明 | 126| ------- | ------- | ------- | ------- | 127| content | string | 是 | 原子化服务menuBar中的标题内容。| 128 129**示例:** 130 131```ts 132import { UIAbility } from '@kit.AbilityKit'; 133import { UIContext, AtomicServiceBar, window } from '@kit.ArkUI'; 134import { hilog } from '@kit.PerformanceAnalysisKit'; 135export default class EntryAbility extends UIAbility { 136 onWindowStageCreate(windowStage: window.WindowStage) { 137 // Main window is created, set main page for this ability 138 hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate'); 139 windowStage.loadContent('pages/Index', (err, data) => { 140 let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); 141 let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 142 if (atomicServiceBar != undefined) { 143 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.'); 144 atomicServiceBar.setTitleContent('text2'); 145 } else { 146 hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.'); 147 } 148 }); 149 } 150} 151``` 152 153## setTitleFontStyle<sup>11+</sup> 154 155setTitleFontStyle(font:FontStyle):void 156 157通过该方法设置原子化服务menuBar的字体样式。 158> **说明:** 159> 160> 从API version 12开始原子化服务menuBar样式变更,menuBar的标题默认隐藏,通过该接口无法改变menuBar的字体样式。 161 162**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 163 164**系统能力:** SystemCapability.ArkUI.ArkUI.Full。 165 166**参数:** 167 168| 参数名 | 类型 | 必填 | 说明 | 169| ------ | ------ | ------ | ------ | 170| font | [FontStyle](arkui-ts/ts-appendix-enums.md#fontstyle) | 是 | 原子化服务menuBar中的字体样式。 | 171 172**示例:** 173 174```ts 175import { UIAbility } from '@kit.AbilityKit'; 176import { UIContext, AtomicServiceBar, window } from '@kit.ArkUI'; 177import { hilog } from '@kit.PerformanceAnalysisKit'; 178export default class EntryAbility extends UIAbility { 179 onWindowStageCreate(windowStage: window.WindowStage) { 180 // Main window is created, set main page for this ability 181 hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate'); 182 windowStage.loadContent('pages/Index', (err, data) => { 183 let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); 184 let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 185 if (atomicServiceBar != undefined) { 186 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.'); 187 atomicServiceBar.setTitleFontStyle(FontStyle.Normal); 188 } else { 189 hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.'); 190 } 191 }); 192 } 193} 194``` 195 196## setIconColor<sup>11+</sup> 197 198setIconColor(color:Nullable<Color | number | string>): void 199 200通过该方法设置原子化服务图标的颜色。 201> **说明:** 202> 203> 从API version 12开始原子化服务menuBar样式变更,menuBar默认隐藏,悬浮按钮图标不予用户设置,通过该接口无法改变menuBar的图标颜色。 204 205**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 206 207**系统能力:** SystemCapability.ArkUI.ArkUI.Full 208 209**参数:** 210 211| 参数名 | 类型 | 必填 | 说明 | 212| ------- | ------- | ------- | ------- | 213| color | Nullable\<[Color](arkui-ts/ts-appendix-enums.md#color) \| number \| string> | 是 | 原子化服务图标的颜色,undefined代表使用默认颜色。number为HEX格式颜色,支持rgb或者argb,示例:0xffffff。string为rgb或者argb格式颜色,示例:'#ffffff'。 | 214 215 216**示例:** 217 218```ts 219import { UIAbility } from '@kit.AbilityKit'; 220import { UIContext, AtomicServiceBar, window } from '@kit.ArkUI'; 221import { hilog } from '@kit.PerformanceAnalysisKit'; 222export default class EntryAbility extends UIAbility { 223 onWindowStageCreate(windowStage: window.WindowStage) { 224 // Main window is created, set main page for this ability 225 hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate'); 226 windowStage.loadContent('pages/Index', (err, data) => { 227 let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); 228 let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 229 if (atomicServiceBar != undefined) { 230 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.'); 231 atomicServiceBar.setIconColor(0x12345678); 232 } else { 233 hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.'); 234 } 235 }); 236 } 237} 238``` 239 240## getBarRect<sup>15+</sup> 241 242getBarRect(): Frame 243 244获取原子化服务menuBar相对窗口的布局信息。 245> **说明:** 246> 247> 布局信息包含了原子化服务menuBar的左右margin。 248 249**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 250 251**系统能力:** SystemCapability.ArkUI.ArkUI.Full 252 253**返回值:** 254 255| 类型 | 说明 | 256| ----------------- | ------------- | 257| [Frame](./js-apis-arkui-graphics.md#frame) | 原子化服务menuBar的大小和位置。 | 258 259**示例:** 260 261```ts 262import { AtomicServiceBar } from '@kit.ArkUI'; 263import { hilog } from '@kit.PerformanceAnalysisKit'; 264@Entry 265@Component 266struct Index { 267 build() { 268 Button("getBarRect") 269 .onClick(() => { 270 let uiContext: UIContext = this.getUIContext(); 271 let currentBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar(); 272 if (currentBar != undefined) { 273 let rect = currentBar.getBarRect(); 274 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully. x:' + 275 rect.x + ' y:' + rect.y + ' width:' + rect.width + ' height:' + rect.height); 276 } else { 277 hilog.info(0x0000, 'testTag', 'Get AtomServiceBar failed.'); 278 } 279 }) 280 } 281} 282``` 283