繁体   English   中英

如何获取 android 应用程序的状态栏插图?

[英]How to get statusbar insets for android app?

我正在尝试使我的 android 应用程序“边缘到边缘”(使状态栏和导航栏半透明)。 我已经在网上阅读了很多关于这个主题的文章,但是由于现在已经弃用了很多方法和类,所以我尝试使用新的方法来编写它。 该应用程序在我的运行 android 11 的物理三星手机上运行正常,但是在运行 android 11 的我的 android 工作室模拟器上启动该应用程序时,它给了我获取插入的运行时错误和错误:查看代码 10。

代码(mainFragment.kt 中的 onCreateView()):

binding.appbar.setOnApplyWindowInsetsListener { view, windowInsets ->
  val insets = windowInsets.getInsets(WindowInsets.Type.statusBars())
  view.updatePadding(top = insets.top)
  windowInsets
}

错误:

java.lang.NoSuchMethodError: No static method statusBars()I in class Landroid/view/WindowInsets$Type; or its super classes (declaration of 'android.view.WindowInsets$Type' appears in /system/framework/framework.jar!classes3.dex)
.MainFragment$onCreateView$1.onApplyWindowInsets(MainFragment.kt:44)

更新:运行 android 11 的模拟器也没有问题,现在我认为我必须为较低的 API 做不同的工作? 但究竟如何?!

尝试使用您在 androidX 库中使用的相同方法。

ViewCompat.setOnApplyWindowInsetsListener(view, listener)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM