2

I'm trying to make my android app "edge to edge" (make statusbar and navbar translucent). I've read many articles online about this topic but since so many methods and classes are deprecated now, I tried to write it using new ways. The app runs Ok on my physical Samsung phone running android 11, but it gives me runtime error for getting insets while launching the app on my android studio emulator running android 10. Take a look at the code and error:

code (onCreateView() in mainFragment.kt):

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

error:

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)

update: There is also no problem with an emulator running android 11! Now I think I had to do the job differently for lower APIs, but how exactly?!

  • I got the opposite happening to me. I couldn't find an answer. See https://stackoverflow.com/questions/65749945/right-way-to-get-system-insets – Madushan Feb 11 '21 at 02:14
  • I think it's not the opposite but rather it's exactly the same problem. I think I found a workaround for this on this following page but I didn't have time to implement it yet. Take a look: https://www.raywenderlich.com/18393648-window-insets-and-keyboard-animations-tutorial-for-android-11 @Madushan – Reza Dizaji Feb 12 '21 at 02:17
  • Unfortunately this doesn't work for Compose. `ViewCompat.setOnApplyWindowInsetsListener` doesn't seem to fire when the `AmbientView` is used. It might work for the regular view toolkit though. (Or I may be using Compose wrong) – Madushan Feb 12 '21 at 10:19

1 Answers1

1

Try to use the same method that you're using from the androidX lib.

ViewCompat.setOnApplyWindowInsetsListener(view, listener)
Mahmoud
  • 2,683
  • 1
  • 30
  • 32