如何使用Android在Xamarin中获得根布局?

Ehs*_*adi 2 c# android android-activity xamarin

我正在使用Xamarin for Android。我知道我可以为根布局分配一个ID并通过以下代码获取它:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/Root"
Run Code Online (Sandbox Code Playgroud)

并在C#中使用:

var mLayout = (LinearLayout)FindViewById(Resource.Id.Root);
Run Code Online (Sandbox Code Playgroud)

我需要的是一种无需ID即可获取根布局的方法。像这样的东西:

var mLayout = GetRootLayout();
Run Code Online (Sandbox Code Playgroud)

Art*_*nov 5

在您的活动中,只需致电Window.DecorView.FindViewById (Android.Resource.Id.Content)。