如何使用android在Xamarin中获得root布局?

时间:2015-06-14 06:24:18

标签: c# android android-activity xamarin

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/Root"

并在C#中使用:

var mLayout = (LinearLayout)FindViewById(Resource.Id.Root);

我需要的是一种可以在不需要ID的情况下获得根布局的方法。像这样的东西:

var mLayout = GetRootLayout();

1 个答案:

答案 0 :(得分:3)

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