荣耀400pro手机在uni-app获取屏幕高度时没有包含底部控制栏高度

荣耀400pro手机在uni-app获取屏幕高度时没有包含底部控制栏高度

开发环境 版本号 项目创建方式
Windows Windows 11 专业版(23H2) HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

HBuilderX类型:正式

HBuilderX版本号:4.86

手机系统:Android

手机系统版本号:Android 16

手机厂商:华为

手机机型:荣耀400pro

页面类型:vue

vue版本:vue2

打包方式:云端

项目创建方式:HBuilderX

操作步骤: 1

预期结果:

"safeAreaInsets": {
"top": 39,
"right": 0,
"bottom": 0,
"left": 0
},
bottom应该>0,windowHeight应该大于safeArea.bottom

实际结果: 1

bug描述: 荣耀400pro手机在获取屏幕高度时没有包含底部控制栏高度 这是我调用uni.getSystemInfoSync()返回的数据

{
"SDKVersion": "",
"appId": "xxxx",
"appLanguage": "zh-Hans",
"appName": "xxxxx",
"appVersion": "2.5.8",
"appVersionCode": 258,
"appWgtVersion": "2.5.8",
"brand": "honor",
"browserName": "chrome",
"browserVersion": "133.0.6943.137",
"deviceBrand": "honor",
"deviceId": "2A3D81805B1D2E970BB69C406484C6BB",
"deviceModel": "DNP-AN00",
"deviceOrientation": "portrait",
"devicePixelRatio": 3.5,
"deviceType": "phone",
"errMsg": "getSystemInfoSync:ok",
"isUniAppX": false,
"language": "zh-CN",
"model": "DNP-AN00",
"oaid": "",
"osAndroidAPILevel": 35,
"osLanguage": "zh-CN",
"osName": "android",
"osTheme": "light",
"osVersion": "15",
"pixelRatio": 3.5,
"platform": "android",
"romName": "MagicUI",
"romVersion": "MagicOS_9.0.0",
"safeArea": {
"left": 0,
"right": 361,
"top": 39,
"bottom": 759,
"width": 361,
"height": 720
},
"safeAreaInsets": {
"top": 39,
"right": 0,
"bottom": 0,
"left": 0
},
"screenHeight": 759,
"screenWidth": 361,
"statusBarHeight": 39,
"system": "Android 15",
"ua": "Mozilla/5.0 (Linux; Android 15; DNP-AN00 Build/HONORDNP-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/133.0.6943.137 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/39.42857)",
"uniCompileVersion": "4.85",
"uniCompilerVersion": "4.85",
"uniPlatform": "app",
"uniRuntimeVersion": "4.85",
"version": "1.9.9.82519",
"windowBottom": 0,
"windowHeight": 759,
"windowTop": 0,
"windowWidth": 361
}

更多关于荣耀400pro手机在uni-app获取屏幕高度时没有包含底部控制栏高度的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于荣耀400pro手机在uni-app获取屏幕高度时没有包含底部控制栏高度的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个已知的Android系统兼容性问题,特别是在荣耀等使用Magic UI系统的设备上。从你提供的系统信息可以看到,safeAreaInsets.bottom为0,但实际底部存在控制栏,这导致windowHeight计算不准确。

问题分析:

  1. screenHeightwindowHeight都为759,说明系统未正确识别底部控制栏区域
  2. safeAreaInsets.bottom为0,但实际设备应该有底部安全区域
  3. safeArea.bottom为759,与screenHeight相同,确认了安全区域计算异常

解决方案:

  1. 使用plus.navigator获取准确高度
const getTrueScreenHeight = () => {
  if (typeof plus !== 'undefined') {
    return plus.navigator.getSafeAreaInsets().bottom 
           ? plus.screen.resolutionHeight 
           : uni.getSystemInfoSync().screenHeight;
  }
  return uni.getSystemInfoSync().screenHeight;
}
  1. 手动计算可用高度
const systemInfo = uni.getSystemInfoSync();
const usableHeight = systemInfo.screenHeight - systemInfo.statusBarHeight;
  1. 使用CSS安全区域适配
.page {
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}
回到顶部