我正在使用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();
答案 0 :(得分:3)
在您的活动中,只需致电Window.DecorView.FindViewById (Android.Resource.Id.Content)
。