【发布时间】:2021-05-14 18:42:09
【问题描述】:
我正在尝试使我的 android 应用程序“边缘到边缘”(使状态栏和导航栏半透明)。我已经在网上阅读了很多关于这个主题的文章,但是由于现在已经弃用了很多方法和类,所以我尝试使用新的方法来编写它。该应用程序在运行 android 11 的三星物理手机上运行正常,但在运行 android 10 的 android studio 模拟器上启动应用程序时,它给了我运行时错误以获取插图。查看代码和错误:
代码(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,我必须以不同的方式完成这项工作,但究竟如何?!
【问题讨论】:
-
我遇到了相反的情况。我找不到答案。见stackoverflow.com/questions/65749945/…
-
我认为这不是相反的,而是完全相同的问题。我想我在下一页找到了解决方法,但我还没有时间实现它。看一看:raywenderlich.com/…@Madushan
-
不幸的是,这不适用于 Compose。使用
AmbientView时,ViewCompat.setOnApplyWindowInsetsListener似乎不会触发。不过,它可能适用于常规视图工具包。 (或者我可能使用 Compose 错误)
标签: android kotlin user-interface