Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get root layout in Xamarin using android?

I`m using Xamarin for Android. I know that i can assign an Id to the root layout and get it via this code :

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

and in C# use :

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

What i need is a method that could get the root layout without needing the ID. something like this:

var mLayout = GetRootLayout();
like image 984
Ehsan Zargar Ershadi Avatar asked May 11 '26 23:05

Ehsan Zargar Ershadi


1 Answers

In your activity just call Window.DecorView.FindViewById (Android.Resource.Id.Content).

like image 143
Artur Shamsutdinov Avatar answered May 14 '26 13:05

Artur Shamsutdinov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!