AndroidUtilCode 获取导航栏高度方法

r1zk6ea1  于 2023-02-04  发布在  Android
关注(0)|答案(1)|浏览(143)

描述 Bug

由于安卓12L新增加了任务栏功能,当前获取导航栏高度方法是不是需要兼容下

  • AndroidUtilCode 的版本:utilcodex:1.30.1
  • 出现 Bug 的设备型号:三星Galaxy Z Fold4
  • 设备的 Android 版本:Android 13

相关代码

int navBarHeight ;
WindowInsetsCompat rootWindowInsets = ViewCompat.getRootWindowInsets(findViewById(android.R.id.content));
if (rootWindowInsets != null) {
  int top = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).top;
  int bottom = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
  int height = Math.abs(bottom - top);
  if (height > 0) {
      navBarHeight = height;
  } else {
      navBarHeight = BarUtils.getNavBarHeight();
  }
}
lymgl2op

lymgl2op1#

目前库内获取的导航栏高度跟用 insets 获取的,在小白条上是不一样的,小白条的本质实际上还是 navigation,这里最好还是用回 insets-api 来获取吧

相关问题