在Stage模型中,WindowStage/Window可以通过loadContent接口加载页面并创建UI的实例,并将页面内容渲染到关联的窗口中,以是UI实例和窗口是逐一关联的。一些全局的UI接口是和具体UI实例的执行上下文干系的,在当前接口调用时,通过追溯调用链跟踪到UI的上下文,来确定具体的UI实例。若在非UI页面中或者一些异步回调中调用这类接口,大概无法跟踪到当前UI的上下文,导致接口执行失败。
@ohos.window在API version 10 新增getUIContext接口,获取UI上下文实例UIContext对象,使用UIContext对象提供的替代方法,可以直接作用在对应的UI实例上。
阐明:
本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
示例效果请以真机运举动准,当前IDE预览器不支持。
UICon文本
以下API需先使用ohos.window中的getUIContext()方法获取UIContext实例,再通过此实例调用对应方法。本文中UIContext对象以uiContext表示。
getFont的
getFont(): 字体
获取Font对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明字体返回Font实例对象。 示例:
getComponentUtils
getComponentUtils(): 组件实用程序
获取ComponentUtils对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明组件实用程序返回ComponentUtils实例对象。 示例:
- uiContext.getComponentUtils();
复制代码 getUIInspector
getUIInspector(): UIInspector
获取UIInspector对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明UIInspector(UI检查器)返回UIInspector实例对象。 示例:
- uiContext.getUIInspector();
复制代码 getMediaQuery
getMediaQuery(): MediaQuery
获取MediaQuery对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明MediaQuery(媒体查询)返回MediaQuery实例对象。 示例:
- uiContext.getMediaQuery();
复制代码 get路由器
getRouter(): 路由器
获取Router对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明路由器返回Router实例对象。 示例:
getPromptAction
getPromptAction(): 提示操纵
获取PromptAction对象。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明提示操纵返回PromptAction实例对象。 示例:
- uiContext.getPromptAction();
复制代码 animate设置为
animateTo(value: AnimateParam, event: () => void): void
提供animateTo接口来指定由于闭包代码导致的状态变革插入过渡动效。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明价值AnimateParam是设置动画效果干系参数。变乱() => 无效是指定显示动效的闭包函数,在闭包函数中导致的状态变革系统会主动插入过渡动画。 示例:
- // xxx.ets
- @Entry
- @Component
- struct AnimateToExample {
- @State widthSize: number = 250
- @State heightSize: number = 100
- @State rotateAngle: number = 0
- private flag: boolean = true
- build() {
- Column() {
- Button('change size')
- .width(this.widthSize)
- .height(this.heightSize)
- .margin(30)
- .onClick(() => {
- if (this.flag) {
- uiContext.animateTo({
- duration: 2000,
- curve: Curve.EaseOut,
- iterations: 3,
- playMode: PlayMode.Normal,
- onFinish: () => {
- console.info('play end')
- }
- }, () => {
- this.widthSize = 150
- this.heightSize = 60
- })
- } else {
- uiContext.animateTo({}, () => {
- this.widthSize = 250
- this.heightSize = 100
- })
- }
- this.flag = !this.flag
- })
- Button('change rotate angle')
- .margin(50)
- .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
- .onClick(() => {
- uiContext.animateTo({
- duration: 1200,
- curve: Curve.Friction,
- delay: 500,
- iterations: -1, // 设置-1表示动画无限循环
- playMode: PlayMode.Alternate,
- onFinish: () => {
- console.info('play end')
- }
- }, () => {
- this.rotateAngle = 90
- })
- })
- }.width('100%').margin({ top: 5 })
- }
- }
复制代码 showAlertDialog
showAlertDialog(选项:AlertDialogParamWithConfirm |AlertDialogParamWithButtons |AlertDialogParamWithOptions):无效
显示警告弹窗组件,可设置文本内容与相应回调。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项警报对话框ParamWithConfirm |AlertDialogParamWithButtons |AlertDialogParamWithOptions是定义并显示AlertDialog组件。 示例:
- uiContext.showAlertDialog(
- {
- title: 'title',
- message: 'text',
- autoCancel: true,
- alignment: DialogAlignment.Bottom,
- offset: { dx: 0, dy: -20 },
- gridCount: 3,
- confirm: {
- value: 'button',
- action: () => {
- console.info('Button-clicking callback')
- }
- },
- cancel: () => {
- console.info('Closed callbacks')
- }
- }
- )
复制代码 showActionSheet
showActionSheet(value: ActionSheetOptions): void
定义列表弹窗并弹出。
系统本领:SystemCapability.ArkUI.ArkUI.Full
ActionSheetOptions参数:
参数名类型必填阐明标题资源 |字符串是弹窗标题。消息资源 |字符串是弹窗内容。主动取消布尔否点击遮障层时,是否关闭弹窗。
默认值:true确认{
值:ResourceStr,
操纵:() => void
}否确认按钮的文本内容和点击回调。
默认值:
value:按钮文本内容。
action: 按钮选中时的回调。取消() => 无效否点击遮障层关闭dialog时的回调。对准对话框对齐否弹窗在竖直方向上的对齐方式。
默认值:DialogAlignment.Bottom抵消{
dx:长度,
dy:长度
}否弹窗相对alignment所在位置的偏移量。{
dx:0,dy
:0
}床单数组<SheetInfo>是设置选项内容,每个选择项支持设置图片、文本和选中的回调。 SheetInfo接口阐明:
参数名类型必填阐明标题资源链是选项的文本内容。图标资源链否选项的图标,默认无图标显示。行动()=>void是选项选中的回调。 示例:
- uiContext.showActionSheet({
- title: 'ActionSheet title',
- message: 'message',
- autoCancel: true,
- confirm: {
- value: 'Confirm button',
- action: () => {
- console.log('Get Alert Dialog handled')
- }
- },
- cancel: () => {
- console.log('actionSheet canceled')
- },
- alignment: DialogAlignment.Bottom,
- offset: { dx: 0, dy: -10 },
- sheets: [
- {
- title: 'apples',
- action: () => {
- console.log('apples')
- }
- },
- {
- title: 'bananas',
- action: () => {
- console.log('bananas')
- }
- },
- {
- title: 'pears',
- action: () => {
- console.log('pears')
- }
- }
- ]
- })
复制代码 showDatePicker对话框
showDatePickerDialog(选项:DatePickerDialogOptions):无效
定义日期滑动选择器弹窗并弹出。
系统本领:SystemCapability.ArkUI.ArkUI.Full
DatePickerDialogOptions参数:
参数名类型必填阐明开始日期否设置选择器的起始日期。
默认值:Date('1970-1-1')竣事日期否设置选择器的竣事日期。
默认值:Date('2100-12-31')选择日期否设置当前选中的日期。
默认值:当前系统日期月球布尔否日期是否显示为夏历。
默认值:falseshow时间布尔否是否展示时间项。
默认值:false使用MilitaryTime布尔否展示时间是否为24小时制。
默认值:false消失文本样式PickerTextStyle否设置所有选项中最上和最下两个选项的文本颜色、字号、字体粗细。文本样式PickerTextStyle否设置所有选项中除了最上、最下及选中项以外的文本颜色、字号、字体粗细。selectedTextStylePickerTextStyle否设置选中项的文本颜色、字号、字体粗细。onAccept(值:DatePickerResult) => void否点击弹窗中的“确定”按钮时触发该回调。on取消() => 无效否点击弹窗中的“取消”按钮时触发该回调。onChange(值:DatePickerResult) => void否滑动弹窗中的滑动选择器使当前选中项改变时触发该回调。 示例:
- let selectedDate: Date = new Date("2010-1-1")
- uiContext.showDatePickerDialog({
- start: new Date("2000-1-1"),
- end: new Date("2100-12-31"),
- selected: selectedDate,
- onAccept: (value: DatePickerResult) => {
- // 通过Date的setFullYear方法设置按下确定按钮时的日期,这样当弹窗再次弹出时显示选中的是上一次确定的日期
- selectedDate.setFullYear(Number(value.year), Number(value.month), Number(value.day))
- console.info("DatePickerDialog:onAccept()" + JSON.stringify(value))
- },
- onCancel: () => {
- console.info("DatePickerDialog:onCancel()")
- },
- onChange: (value: DatePickerResult) => {
- console.info("DatePickerDialog:onChange()" + JSON.stringify(value))
- }
- })
复制代码 showTimePicker对话框
showTimePickerDialog(选项:TimePickerDialogOptions):无效
定义时间滑动选择器弹窗并弹出。
系统本领:SystemCapability.ArkUI.ArkUI.Full
TimePickerDialogOptions参数:
参数名类型必填阐明选择日期否设置当前选中的时间。
默认值:当前系统时间使用MilitaryTime布尔否展示时间是否为24小时制,默认为12小时制。
默认值:false消失文本样式PickerTextStyle否设置所有选项中最上和最下两个选项的文本颜色、字号、字体粗细。文本样式PickerTextStyle否设置所有选项中除了最上、最下及选中项以外的文本颜色、字号、字体粗细。selectedTextStylePickerTextStyle否设置选中项的文本颜色、字号、字体粗细。onAccept(值:TimePickerResult) => void否点击弹窗中的“确定”按钮时触发该回调。on取消() => 无效否点击弹窗中的“取消”按钮时触发该回调。onChange(值:TimePickerResult) => void否滑动弹窗中的选择器使当前选中时间改变时触发该回调。 示例:
- class sethours{
- selectTime: Date = new Date('2020-12-25T08:30:00')
- hours(h:number,m:number){
- this.selectTime.setHours(h,m)
- }
- }
- uiContext.showTimePickerDialog({
- selected: this.selectTime,
- onAccept: (value: TimePickerResult) => {
- // 设置selectTime为按下确定按钮时的时间,这样当弹窗再次弹出时显示选中的为上一次确定的时间
- let time = new sethours()
- if(value.hour&&value.minute){
- time.hours(value.hour, value.minute)
- }
- console.info("TimePickerDialog:onAccept()" + JSON.stringify(value))
- },
- onCancel: () => {
- console.info("TimePickerDialog:onCancel()")
- },
- onChange: (value: TimePickerResult) => {
- console.info("TimePickerDialog:onChange()" + JSON.stringify(value))
- }
- })
复制代码 showTextPicker对话框
showTextPickerDialog(选项:TextPickerDialogOptions):无效
定义文本滑动选择器弹窗并弹出。
系统本领:SystemCapability.ArkUI.ArkUI.Full
TextPickerDialogOptions参数:
参数名类型必填阐明范围字符串[] |资源|TextPickerRangeContent[]是设置文本选择器的选择范围。不可设置为空数组,若设置为空数组,则不弹出弹窗。选择数否设置选中项的索引值。
默认值:0价值字符串否设置选中项的文本内容。当设置了selected参数时,该参数不生效。如果设置的value值不在range范围内,则默认取range第一个元素。defaultPickerItemHeight数字 |字符串否设置选择器中选项的高度。消失文本样式PickerTextStyle否设置所有选项中最上和最下两个选项的文本颜色、字号、字体粗细。文本样式PickerTextStyle否设置所有选项中除了最上、最下及选中项以外的文本颜色、字号、字体粗细。selectedTextStylePickerTextStyle否设置选中项的文本颜色、字号、字体粗细。onAccept(值:TextPickerResult) => void否点击弹窗中的“确定”按钮时触发该回调。on取消() => 无效否点击弹窗中的“取消”按钮时触发该回调。onChange(值:TextPickerResult) => void否滑动弹窗中的选择器使当前选中项改变时触发该回调。 示例:
- { class setvalue{
- select: number = 2
- set(val:number){
- this.select = val
- }
- }
- class setvaluearr{
- select: number[] = []
- set(val:number[]){
- this.select = val
- }
- }
- let fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5']
- uiContext.showTextPickerDialog({
- range: this.fruits,
- selected: this.select,
- onAccept: (value: TextPickerResult) => {
- // 设置select为按下确定按钮时候的选中项index,这样当弹窗再次弹出时显示选中的是上一次确定的选项
- let setv = new setvalue()
- let setvarr = new setvaluearr()
- if(value.index){
- value.index instanceof Array?setvarr.set(value.index) : setv.set(value.index)
- }
- console.info("TextPickerDialog:onAccept()" + JSON.stringify(value))
- },
- onCancel: () => {
- console.info("TextPickerDialog:onCancel()")
- },
- onChange: (value: TextPickerResult) => {
- console.info("TextPickerDialog:onChange()" + JSON.stringify(value))
- }
- })
复制代码 createAnimator
createAnimator(options: AnimatorOptions): AnimatorResult
定义Animator类。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项动画师选项是定义动画选项。 返回值:
类型阐明动画师结果Animator结果接口。 示例:
- import { AnimatorOptions } from '@ohos.animator';
- let options:AnimatorOptions = {
- duration: 1500,
- easing: "friction",
- delay: 0,
- fill: "forwards",
- direction: "normal",
- iterations: 3,
- begin: 200.0,
- end: 400.0
- };
- uiContext.createAnimator(options);
复制代码 runScopedTask
runScopedTask(callback: () => void): 无效
在当前UI上下文执行传入的回调函数。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明回调() => 无效是回调函数 示例:
- uiContext.runScopedTask(
- () => {
- console.log('Succeeded in runScopedTask');
- }
- );
复制代码 字体
以下API需先使用UIContext中的getFont()方法获取到Font对象,再通过该对象调用对应方法。
注册字体
registerFont(options: font.FontOptions):无效
在字体管理中注册自定义字体。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项字体。字体选项是注册的自定义字体信息。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let font:Font = uiContext.getFont();
- font.registerFont({
- familyName: 'medium',
- familySrc: '/font/medium.ttf'
- });
复制代码 getStstemFontList
getSystemFontList():数组<字符串>
获取系统支持的字体名称列表。
系统本领:SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明数组<字符串>系统的字体名列表。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let font:Font|undefined = uiContext.getFont();
- if(font){
- font.getSystemFontList()
- }
复制代码 getFontByName
getFontByName(fontName: string): 字体。字体信息
根据传入的系统字体名称获取系统字体的干系信息。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明font名称字符串是系统的字体名。 返回值:
类型阐明字体信息字体的具体信息 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let font:Font|undefined = uiContext.getFont();
- if(font){
- font.getFontByName('Sans Italic')
- }
复制代码 组件实用程序
以下API需先使用UIContext中的getComponentUtils()方法获取到ComponentUtils对象,再通过该对象调用对应方法。
getRectangleById
getRectangleById(id:字符串):componentUtils.ComponentInfo
获取组件大小、位置、平移缩放旋转及仿射矩阵属性信息。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明同上字符串是组件唯一标识id。 返回值:
类型阐明ComponentInfo组件大小、位置、平移缩放旋转及仿射矩阵属性信息。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let componentUtils:ComponentUtils = uiContext.getComponentUtils();
- let modePosition = componentUtils.getRectangleById("onClick");
- let localOffsetWidth = modePosition.size.width;
- let localOffsetHeight = modePosition.size.height;
复制代码 UIInspector(UI检查器)
以下API需先使用UIContext中的getUIInspector()方法获取到UIInspector对象,再通过该对象调用对应方法。
createComponentObserver
createComponentObserver(id: string):检查器。组件观察者
注册组件布局和绘制完成回调通知。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明同上字符串是指定组件id。 返回值:
类型阐明组件观察者组件回调变乱监听句柄,用于注册和取消注册监听回调。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let inspector:UIInspector = uiContext.getUIInspector();
- let listener = inspector.createComponentObserver('COMPONENT_ID');
复制代码 MediaQuery(媒体查询)
以下API需先使用UIContext中的getMediaQuery()方法获取到MediaQuery对象,再通过该对象调用对应方法。
匹配媒体同步
matchMediaSync(条件:字符串): mediaQuery.MediaQueryListener
设置媒体查询的查询条件,并返回对应的监听句柄。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明条件字符串是媒体变乱的匹配条件,具体可参考媒体查询语法规则。 返回值:
类型阐明MediaQueryListener媒体变乱监听句柄,用于注册和去注册监听回调。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- let mediaquery: MediaQuery = uiContext.getMediaQuery();
- let listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件
复制代码 路由器
以下API需先使用UIContext中的getRouter()方法获取到Router对象,再通过该对象调用对应方法。
pushUrl
pushUrl(options: router.RouterOptions):允许<无效>
跳转到应用内的指定页面。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项路由器。路由器选项是跳转页面形貌信息。 返回值:
类型阐明允许<无效>非常返回结果。 错误码:
以下错误码的具体介绍,请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001如果未找到 UI 执行上下文。100002如果 URI 不存在。100003如果页面推送过多。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- try {
- router.pushUrl({
- url: 'pages/routerpage2',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- })
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushUrl failed, code is ${code}, message is ${message}`);
- }
复制代码 pushUrl
pushUrl(options: router.RouterOptions,回调:AsyncCallback<void>):void
跳转到应用内的指定页面。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项路由器。路由器选项是跳转页面形貌信息。回调AsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍,请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001如果未找到 UI 执行上下文。100002如果 URI 不存在。100003如果页面推送过多。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- router.pushUrl({
- url: 'pages/routerpage2',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushUrl failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('pushUrl success');
- })
复制代码 pushUrl
pushUrl(options: router.RouterOptions,模式:路由器。RouterMode):Promise<void>
跳转到应用内的指定页面。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项路由器。路由器选项是跳转页面形貌信息。模式路由器。路由器模式是跳转页面使用的模式。 返回值:
类型阐明允许<无效>非常返回结果。 错误码:
以下错误码的具体介绍,请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001如果未找到 UI 执行上下文。100002如果 URI 不存在。100003如果页面推送过多。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- try {
- routerF.pushUrl({
- url: 'pages/routerpage2',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, rtm.Standard)
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushUrl failed, code is ${code}, message is ${message}`);
- }
复制代码 pushUrl
pushUrl(options: router.RouterOptions, mode: router.RouterMode, callback: AsyncCallback<void>): void
跳转到应用内的指定页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.RouterOptions是跳转页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found.100002if the uri is not exist.100003if the pages are pushed too much. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- routerF.pushUrl({
- url: 'pages/routerpage2',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, rtm.Standard, (err) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushUrl failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('pushUrl success');
- })
复制代码 替换 Url
replaceUrl(选项:路由器。RouterOptions):允许<无效>
用应用内的某个页面替换当前页面,并烧毁被替换的页面。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项路由器。路由器选项是替换页面形貌信息。 返回值:
类型阐明允许<无效>非常返回结果。 错误码:
以下错误码的具体介绍,请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001如果未找到UI执行上下文,则仅投入标准系统。200002如果 URI 不存在。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- try {
- router.replaceUrl({
- url: 'pages/detail',
- params: {
- data1: 'message'
- }
- })
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
- }
复制代码 替换 Url
replaceUrl(选项:路由器。RouterOptions,回调:AsyncCallback<void>):void
用应用内的某个页面替换当前页面,并烧毁被替换的页面。
系统本领:SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明选项路由器。路由器选项是替换页面形貌信息。回调AsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍,请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001如果未找到UI执行上下文,则仅投入标准系统。200002如果 URI 不存在。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- router.replaceUrl({
- url: 'pages/detail',
- params: {
- data1: 'message'
- }
- }, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('replaceUrl success');
- })
复制代码 替换 Url
replaceUrl(options: router.RouterOptions, mode: router.RouterMode): Promise<void>
用应用内的某个页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.RouterOptions是替换页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。 返回值:
类型阐明Promise<void>非常返回结果。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if can not get the delegate, only throw in standard system.200002if the uri is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- try {
- routerF.replaceUrl({
- url: 'pages/detail',
- params: {
- data1: 'message'
- }
- }, rtm.Standard)
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
- }
复制代码 replaceUrl
replaceUrl(options: router.RouterOptions, mode: router.RouterMode, callback: AsyncCallback<void>): void
用应用内的某个页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.RouterOptions是替换页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found, only throw in standard system.200002if the uri is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- routerF.replaceUrl({
- url: 'pages/detail',
- params: {
- data1: 'message'
- }
- }, rtm.Standard, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('replaceUrl success');
- });
复制代码 pushNamedRoute
pushNamedRoute(options: router.NamedRouterOptions): Promise<void>
跳转到指定的命名路由页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是跳转页面形貌信息。 返回值:
类型阐明Promise<void>非常返回结果。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found.100003if the pages are pushed too much.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- try {
- router.pushNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- })
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
- }
复制代码 pushNamedRoute
pushNamedRoute(options: router.NamedRouterOptions, callback: AsyncCallback<void>): void
跳转到指定的命名路由页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是跳转页面形貌信息。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found.100003if the pages are pushed too much.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- router.pushNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('pushNamedRoute success');
- })
复制代码 pushNamedRoute
pushNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode): Promise<void>
跳转到指定的命名路由页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是跳转页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。 返回值:
类型阐明Promise<void>非常返回结果。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found.100003if the pages are pushed too much.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- try {
- routerF.pushNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, rtm.Standard)
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
- }
复制代码 pushNamedRoute
pushNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode, callback: AsyncCallback<void>): void
跳转到指定的命名路由页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是跳转页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found.100003if the pages are pushed too much.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- routerF.pushNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message',
- data2: {
- data3: [123, 456, 789]
- }
- }
- }, rtm.Standard, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('pushNamedRoute success');
- })
复制代码 replaceNamedRoute
replaceNamedRoute(options: router.NamedRouterOptions): Promise<void>
用指定的命名路由页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是替换页面形貌信息。 返回值:
类型阐明Promise<void>非常返回结果。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found, only throw in standard system.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- try {
- router.replaceNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message'
- }
- })
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
- }
复制代码 replaceNamedRoute
replaceNamedRoute(options: router.NamedRouterOptions, callback: AsyncCallback<void>): void
用指定的命名路由页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是替换页面形貌信息。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found, only throw in standard system.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router:Router = uiContext.getRouter();
- router.replaceNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message'
- }
- }, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('replaceNamedRoute success');
- })
复制代码 replaceNamedRoute
replaceNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode): Promise<void>
用指定的命名路由页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是替换页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。 返回值:
类型阐明Promise<void>非常返回结果。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if can not get the delegate, only throw in standard system.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- try {
- routerF.replaceNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message'
- }
- }, rtm.Standard)
- } catch (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
- }
复制代码 replaceNamedRoute
replaceNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode, callback: AsyncCallback<void>): void
用指定的命名路由页面替换当前页面,并烧毁被替换的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.NamedRouterOptions是替换页面形貌信息。moderouter.RouterMode是跳转页面使用的模式。callbackAsyncCallback<void>是非常相应回调。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found, only throw in standard system.100004if the named route is not exist. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- import router from '@ohos.router';
- let routerF:Router = uiContext.getRouter();
- class routerTmp{
- Standard:router.RouterMode = router.RouterMode.Standard
- }
- let rtm:routerTmp = new routerTmp()
- routerF.replaceNamedRoute({
- name: 'myPage',
- params: {
- data1: 'message'
- }
- }, rtm.Standard, (err: Error) => {
- if (err) {
- let message = (err as BusinessError).message;
- let code = (err as BusinessError).code;
- console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
- return;
- }
- console.info('replaceNamedRoute success');
- });
复制代码 back
back(options?: router.RouterOptions ): void
返回上一页面或指定的页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.RouterOptions否返回页面形貌信息,此中参数url指路由跳转时会返回到指定url的界面,如果页面栈上没有url页面,则不相应该情况。如果url未设置,则返回上一页,页面不会重新构建,页面栈里面的page不会接纳,出栈后会被接纳。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- router.back({url:'pages/detail'});
复制代码 clear
clear(): void
清空页面栈中的所有汗青页面,仅保留当前页面作为栈顶页面。
系统本领: SystemCapability.ArkUI.ArkUI.Full
示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- router.clear();
复制代码 getLength
getLength(): string
获取当前在页面栈内的页面数量。
系统本领: SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明string页面数量,页面栈支持最大数值是32。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- let size = router.getLength();
- console.log('pages stack size = ' + size);
复制代码 getState
getState(): router.RouterState
获取当前页面的状态信息。
系统本领: SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明RouterState页面状态信息。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- let page = router.getState();
- console.log('current index = ' + page.index);
- console.log('current name = ' + page.name);
- console.log('current path = ' + page.path);
复制代码 showAlertBeforeBackPage
showAlertBeforeBackPage(options: router.EnableAlertOptions): void
开启页面返回扣问对话框。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionsrouter.EnableAlertOptions是文本弹窗信息形貌。 错误码:
以下错误码的具体介绍请拜见ohos.router(页面路由)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- try {
- router.showAlertBeforeBackPage({
- message: 'Message Info'
- });
- } catch(error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showAlertBeforeBackPage failed, code is ${code}, message is ${message}`);
- }
复制代码 hideAlertBeforeBackPage
hideAlertBeforeBackPage(): void
禁用页面返回扣问对话框。
系统本领: SystemCapability.ArkUI.ArkUI.Full
示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- router.hideAlertBeforeBackPage();
复制代码 getParams
getParams(): Object
获取发起跳转的页面往当前页传入的参数。
系统本领: SystemCapability.ArkUI.ArkUI.Full
返回值:
类型阐明object发起跳转的页面往当前页传入的参数。 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let router: Router = uiContext.getRouter();
- router.getParams();
复制代码 PromptAction
以下API需先使用UIContext中的getPromptAction()方法获取到PromptAction对象,再通过该对象调用对应方法。
showToast
showToast(options: promptAction.ShowToastOptions): void
创建并显示文本提示框。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionspromptAction.ShowToastOptions是文本弹窗选项。 错误码:
以下错误码的具体介绍请拜见ohos.promptAction(弹窗)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let promptAction: PromptAction = uiContext.getPromptAction();
- try {
- promptAction.showToast({
- message: 'Message Info',
- duration: 2000
- });
- } catch (error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showToast args error code is ${code}, message is ${message}`);
- };
复制代码 showDialog
showDialog(options: promptAction.ShowDialogOptions, callback: AsyncCallback<promptAction.ShowDialogSuccessResponse>): void
创建并显示对话框,对话框相应结果异步返回。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionspromptAction.ShowDialogOptions是页面显示对话框信息形貌。callbackAsyncCallback<promptAction.ShowDialogSuccessResponse>是对话框相应结果回调。 错误码:
以下错误码的具体介绍请拜见ohos.promptAction(弹窗)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- class buttonsMoabl {
- text: string = ""
- color: string = ""
- }
- let promptAction: PromptAction = uiContext.getPromptAction();
- try {
- promptAction.showDialog({
- title: 'showDialog Title Info',
- message: 'Message Info',
- buttons: [
- {
- text: 'button1',
- color: '#000000'
- } as buttonsMoabl,
- {
- text: 'button2',
- color: '#000000'
- } as buttonsMoabl
- ]
- }, (err, data) => {
- if (err) {
- console.info('showDialog err: ' + err);
- return;
- }
- console.info('showDialog success callback, click button: ' + data.index);
- });
- } catch (error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showDialog args error code is ${code}, message is ${message}`);
- };
复制代码 showDialog
showDialog(options: promptAction.ShowDialogOptions): Promise<promptAction.ShowDialogSuccessResponse>
创建并显示对话框,对话框相应后同步返回结果。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionspromptAction.ShowDialogOptions是对话框选项。 返回值:
类型阐明Promise<promptAction.ShowDialogSuccessResponse>对话框相应结果。 错误码:
以下错误码的具体介绍请拜见ohos.promptAction(弹窗)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let promptAction: PromptAction = uiContext.getPromptAction();
- try {
- promptAction.showDialog({
- title: 'Title Info',
- message: 'Message Info',
- buttons: [
- {
- text: 'button1',
- color: '#000000'
- },
- {
- text: 'button2',
- color: '#000000'
- }
- ],
- })
- .then(data => {
- console.info('showDialog success, click button: ' + data.index);
- })
- .catch((err:Error) => {
- console.info('showDialog error: ' + err);
- })
- } catch (error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showDialog args error code is ${code}, message is ${message}`);
- };
复制代码 showActionMenu
showActionMenu(options: promptAction.ActionMenuOptions, callback:promptAction.ActionMenuSuccessResponse):void
创建并显示操纵菜单,菜单相应结果异步返回。
系统本领: SystemCapability.ArkUI.ArkUI.Full。
参数:
参数名类型必填阐明optionspromptAction.ActionMenuOptions是操纵菜单选项。callbackpromptAction.ActionMenuSuccessResponse是菜单相应结果回调。 错误码:
以下错误码的具体介绍请拜见ohos.promptAction(弹窗)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import promptAction from '@ohos.promptAction';
- import { BusinessError } from '@ohos.base';
- class buttonsMoabl {
- text: string = ""
- color: string = ""
- }
- class dataR{
- err:Error = new Error;
- data:promptAction.ActionMenuSuccessResponse | undefined = undefined;
- }
- let dataAMSR:dataR = new dataR()
- let promptActionF: PromptAction = uiContext.getPromptAction();
- try {
- if(dataAMSR.data){
- promptActionF.showActionMenu({
- title: 'Title Info',
- buttons: [
- {
- text: 'item1',
- color: '#666666'
- } as buttonsMoabl,
- {
- text: 'item2',
- color: '#000000'
- } as buttonsMoabl
- ]
- }, (dataAMSR.data))
- if (dataAMSR.err) {
- console.info('showActionMenu err: ' + dataAMSR.err);
- }else{
- console.info('showActionMenu success callback, click button: ' + dataAMSR.data.index);
- }
- }
- } catch (error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showActionMenu args error code is ${code}, message is ${message}`);
- };
复制代码 showActionMenu
showActionMenu(options: promptAction.ActionMenuOptions): Promise<promptAction.ActionMenuSuccessResponse>
创建并显示操纵菜单,菜单相应后同步返回结果。
系统本领: SystemCapability.ArkUI.ArkUI.Full
参数:
参数名类型必填阐明optionspromptAction.ActionMenuOptions是操纵菜单选项。 返回值:
类型阐明Promise<promptAction.ActionMenuSuccessResponse>菜单相应结果。 错误码:
以下错误码的具体介绍请拜见ohos.promptAction(弹窗)错误码。
错误码ID错误信息100001if UI execution context not found. 示例:
- import { ComponentUtils, Font, PromptAction, Router, UIInspector, MediaQuery } from '@ohos.arkui.UIContext';
- import { BusinessError } from '@ohos.base';
- let promptAction: PromptAction = uiContext.getPromptAction();
- try {
- promptAction.showActionMenu({
- title: 'showActionMenu Title Info',
- buttons: [
- {
- text: 'item1',
- color: '#666666'
- },
- {
- text: 'item2',
- color: '#000000'
- },
- ]
- })
- .then(data => {
- console.info('showActionMenu success, click button: ' + data.index);
- })
- .catch((err:Error) => {
- console.info('showActionMenu error: ' + err);
- })
- } catch (error) {
- let message = (error as BusinessError).message;
- let code = (error as BusinessError).code;
- console.error(`showActionMenu args error code is ${code}, message is ${message}`);
- };
复制代码 末了
有许多小伙伴不知道学习哪些鸿蒙开辟技术?不知道必要重点把握哪些鸿蒙应用开辟知识点?而且学习时频繁踩坑,最终浪费大量时间。以是有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。
这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开辟必把握的核心知识要点,内容包含了(ArkTS、ArkUI开辟组件、Stage模型、多端部署、分布式应用开辟、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开辟、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。
希望这一份鸿蒙学习资料可以或许给各人带来资助,有必要的小伙伴自行领取,限时开源,先到先得~无套路领取!!
获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
鸿蒙(HarmonyOS NEXT)最新学习路线
- HarmonOS就业必备技能
- HarmonOS多媒体技术
有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开辟入门教学视频,内容包含:ArkTS、ArkUI、Web开辟、应用模型、资源分类…等知识点。
获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
《鸿蒙 (OpenHarmony)开辟入门教学视频》
《鸿蒙生态应用开辟V2.0白皮书》
《鸿蒙 (OpenHarmony)开辟根本到实战手册》
OpenHarmony北向、南向开辟环境搭建
《鸿蒙开辟根本》
- ArkTS语言
- 安装DevEco Studio
- 运用你的第一个ArkTS应用
- ArkUI声明式UI开辟
- .……
《鸿蒙开辟进阶》
- Stage模型入门
- 网络管理
- 数据管理
- 电话服务
- 分布式应用开辟
- 通知与窗口管理
- 多媒体技术
- 安全技能
- 任务管理
- WebGL
- 国际化开辟
- 应用测试
- DFX面向未来计划
- 鸿蒙系统移植和裁剪定制
- ……
《鸿蒙进阶实战》
- ArkTS实践
- UIAbility应用
- 网络案例
- ……
获取以上完整鸿蒙HarmonyOS学习资料,请点击→纯血版全套鸿蒙HarmonyOS学习资料
总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个寻衅,也是一个时机。只有积极应对变革,不绝学习和提升自己,他们才华在这个厘革的时代中立于不败之地。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |