Share via

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?

Developer technologies | .NET | Xamarin
0 comments No comments

Answer accepted by question author

Anonymous
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.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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