智能客服
你问我答,随时在线为你解决问题

























手机端应用在PC上仍显示为手机样式UI,无法打开全屏。
效果图如下:

一多适配提供帮助开发者快速开发出适配多种类型设备的应用的能力。一多适配开发使用的布局能力包括以下两种方式:
- smListener: mediaquery.MediaQueryListener =
- this.getUIContext().getMediaQuery().matchMediaSync('(orientation: landscape)');
- mdListener: mediaquery.MediaQueryListener =
- this.getUIContext().getMediaQuery().matchMediaSync('(520vp<=width<840vp)');
- lgListener: mediaquery.MediaQueryListener = this.getUIContext().getMediaQuery().matchMediaSync('(840vp<=width)');
-
- // 注册媒体属性变更回调事件,监听屏幕尺寸在页面初始化的时候完成注册。
- public register() {
- this.smListener = this.getUIContext().getMediaQuery().matchMediaSync('(320vp<=width<520vp)');
- this.smListener.on('change', this.isBreakpointSM);
- this.mdListener = this.getUIContext().getMediaQuery().matchMediaSync('(520vp<=width<840vp)');
- this.mdListener.on('change', this.isBreakpointMD);
- this.lgListener = this.getUIContext().getMediaQuery().matchMediaSync('(840vp<=width)');
- this.lgListener.on('change', this.isBreakpointLG);
- }
-
- // 保存屏幕尺寸的断点
- private updateCurrentBreakpoint(breakpoint: string) {
- if (this.currentBreakpoint !== breakpoint) {
- this.currentBreakpoint = breakpoint;
- AppStorage.set<string>('currentBreakpoint', this.currentBreakpoint);
- }
- }
-
- private isBreakpointSM = (mediaQueryResult: mediaquery.MediaQueryResult) => {
- if (mediaQueryResult.matches) {
- this.updateCurrentBreakpoint('sm');
- }
- };
-
- private isBreakpointMD = (mediaQueryResult: mediaquery.MediaQueryResult) => {
- if (mediaQueryResult.matches) {
- this.updateCurrentBreakpoint('md');
- }
- };
-
- private isBreakpointLG = (mediaQueryResult: mediaquery.MediaQueryResult) => {
- if (mediaQueryResult.matches) {
- this.updateCurrentBreakpoint('lg');
- }
- };
-
- @StorageProp('currentBreakpoint') currentBreakpoint: string = 'sm'; // 初始化默认为手机
-
- build() {
- Column() {
- Tabs({
- barPosition: this.currentBreakpoint === BreakpointConstants.BREAKPOINT_LG ? BarPosition.Start : BarPosition.End,
- }) {
- // tab内容
-
- }
- .barWidth(this.currentBreakpoint === 'lg' ?
- $r('app.float.barWidth') : StyleConstants.FULL_WIDTH)
- .barHeight(this.currentBreakpoint === 'lg' ?
- StyleConstants.SIXTY_HEIGHT : $r('app.float.back_width'))
- .vertical(this.currentBreakpoint === 'lg')
- }
- }
-
效果如下:

PC上进行全屏展示:

智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功