uni-app 安卓的tabBar出现问题 不显示图片且高度异常

uni-app 安卓的tabBar出现问题 不显示图片且高度异常

信息类别 详情
产品分类 uniapp/App
PC开发环境 Windows
PC版本号 win11
HBuilderX 正式
HBuilderX版本 4.15
手机系统 Android
手机版本号 Android 13
手机厂商 小米
手机机型 10pro
页面类型 vue
vue版本 vue2
打包方式 云端
项目创建方式 HBuilderX

示例代码:

{
    "tabBar": {  
        "backgroundColor": "white",  
        "color": "#999999",  
        "selectedColor": "#45467A",  
        "borderStyle": "white",  
        "height": "120rpx",  
        "spacing": "8rpx",  
        "iconWidth": "48rpx",  
        "list": [...]  
    }
}

操作步骤:

{
    "tabBar": {  
        "backgroundColor": "white",  
        "color": "#999999",  
        "selectedColor": "#45467A",  
        "borderStyle": "white",  
        "height": "120rpx",  
        "spacing": "8rpx",  
        "iconWidth": "48rpx",  
        "list": [...]  
    }
}

预期结果:

希望app端正常显示

实际结果:

app端显示异常

bug描述:

H5和小程序是正常的,安卓调试图片没有,且高度很大,程序没有对tabbar做额外的处理,ui用的uview,1年前的项目


更多关于uni-app 安卓的tabBar出现问题 不显示图片且高度异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

而且uview的uicon都不正常显示了,之前都好好的,不知道哪个版本开始出现的,uview也更新到了最新版本

更多关于uni-app 安卓的tabBar出现问题 不显示图片且高度异常的实战教程也可以访问 https://www.itying.com/category-93-b0.html


把iconWidth去掉,重新运行下

还真是"height": “120rpx”, “spacing”: “8rpx”, “iconWidth”: “48rpx”,这三个值的原因,之前有想过是这个原因,注释过,没想过,必须卸载本地重装

在 uni-app 中,如果你发现安卓平台的 tabBar 不显示图片且高度异常,可能是由于以下几个原因导致的。你可以按照以下步骤进行排查和修复:

1. 检查图片路径

确保 tabBar 中使用的图片路径是正确的,并且图片文件确实存在。在 uni-app 中,图片路径应该是相对路径或绝对路径。

{
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "static/tabbar/home.png",
        "selectedIconPath": "static/tabbar/home_active.png",
        "text": "首页"
      }
    ]
  }
}

2. 检查图片格式和大小

确保图片格式是支持的格式(如 .png.jpg 等),并且图片大小适中。过大的图片可能会导致渲染问题。

3. 检查 tabBar 配置

确保 tabBar 的配置是正确的,包括 iconPathselectedIconPath 等字段。

{
  "tabBar": {
    "color": "#999999",
    "selectedColor": "#007AFF",
    "backgroundColor": "#FFFFFF",
    "borderStyle": "black",
    "list": [
      {
        "pagePath": "pages/index/index",
        "iconPath": "static/tabbar/home.png",
        "selectedIconPath": "static/tabbar/home_active.png",
        "text": "首页"
      },
      {
        "pagePath": "pages/user/user",
        "iconPath": "static/tabbar/user.png",
        "selectedIconPath": "static/tabbar/user_active.png",
        "text": "我的"
      }
    ]
  }
}

4. 检查 tabBar 的高度

tabBar 的高度可能会受到样式的影响。你可以通过自定义样式来调整 tabBar 的高度。

/* 在 App.vue 或全局样式文件中 */
.uni-tabbar {
  height: 50px; /* 设置为适当的高度 */
}

5. 清除缓存并重新编译

有时候,缓存可能会导致一些问题。你可以尝试清除项目缓存,然后重新编译运行。

# 清除缓存
rm -rf unpackage/dist
rm -rf node_modules

# 重新安装依赖
npm install

# 重新编译运行
npm run dev:mp-weixin

6. 检查 uni-app 版本

确保你使用的 uni-app 版本是最新的,或者至少是一个稳定的版本。某些旧版本可能存在一些已知的 bug。

# 更新 uni-app
npm update @dcloudio/uni-app

7. 检查安卓设备的兼容性

某些安卓设备可能存在兼容性问题。你可以尝试在其他设备上运行,看看问题是否依然存在。

8. 使用自定义 tabBar

如果问题依然无法解决,你可以考虑使用自定义 tabBar 替代原生 tabBar。自定义 tabBar 可以更灵活地控制样式和行为。

<template>
  <view class="custom-tabbar">
    <view class="tabbar-item" @click="switchTab(0)">
      <image :src="currentIndex === 0 ? 'static/tabbar/home_active.png' : 'static/tabbar/home.png'"></image>
      <text :class="{'active': currentIndex === 0}">首页</text>
    </view>
    <view class="tabbar-item" @click="switchTab(1)">
      <image :src="currentIndex === 1 ? 'static/tabbar/user_active.png' : 'static/tabbar/user.png'"></image>
      <text :class="{'active': currentIndex === 1}">我的</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0
    };
  },
  methods: {
    switchTab(index) {
      this.currentIndex = index;
      // 跳转到对应的页面
      uni.switchTab({
        url: index === 0 ? '/pages/index/index' : '/pages/user/user'
      });
    }
  }
};
</script>

<style>
.custom-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: #FFFFFF;
  border-top: 1px solid #CCCCCC;
}
.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tabbar-item image {
  width: 24px;
  height: 24px;
}
.tabbar-item text {
  font-size: 12px;
  color: #999999;
}
.tabbar-item .active {
  color: #007AFF;
}
</style>
回到顶部