Cannot Access WindowInsets

Nathan Sokalski 4,111 Reputation points
2022-03-28T02:54:01.397+00:00

I am attempting to access the WindowInsets in my app, but I am receiving the following message:

Java.Lang.NoSuchMethodError: 'no static method "Landroid/view/WindowInsets$Type;.statusBars()I"'

The expression in my code containing this is (frmPossibleBids is a FrameLayout):

this.frmPossibleBids.RootWindowInsets.GetInsets(WindowInsets.Type.StatusBars()).Top

What am I doing wrong?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,181 Reputation points Microsoft Vendor
    2022-03-28T06:27:42.797+00:00

    Hello,​

    If you want to get WindowInsets, your frmPossibleBids should be attached in the layout.

    So, I add a AddOnAttachStateChangeListener for frmPossibleBids, I can get the top value in the OnViewAttachedToWindow method like following code.

       //add AddOnAttachStateChangeListener  
                   frmPossibleBids.AddOnAttachStateChangeListener(new FrmPossibleBidsttachStateChangeListener());  
         
       // achieve this AddOnAttachStateChangeListener class.  
       internal class FrmPossibleBidsttachStateChangeListener : Java.Lang.Object, View.IOnAttachStateChangeListener  
           {  
             
               public void OnViewAttachedToWindow(View attachedView)  
               {  
         
                 var topValue= attachedView.RootWindowInsets.GetInsets(WindowInsets.Type.StatusBars()).Top;  
               }  
         
               public void OnViewDetachedFromWindow(View detachedView)  
               {  
                     
               }  
           }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.