using Android.Graphics.Drawables; // Get the LinearLayout LinearLayout myLinearLayout = FindViewById(Resource.Id.myLinearLayout); // Set the background resource myLinearLayout.SetBackgroundResource(Resource.Drawable.myBackground);
using Android.Content.Res; // Get the drawable resource Drawable myDrawable = Resources.GetDrawable(Resource.Drawable.myBackground); // Set the background of the LinearLayout with the drawable resource myLinearLayout.SetBackground(myDrawable);In this example, we obtain the drawable resource using the Resources.GetDrawable method. We then set the background of the LinearLayout with SetBackground method using the drawable resource. Package library: Xamarin.Android Note: The SetBackgroundResource method is available from API level 1 onwards. It is recommended to use this method instead of SetBackground as it is more efficient.