Another tough day with Xamarin!
So, today, i am trying to figure out how one can create and use a custom control in Xamarin.Android. I read all the docs and all were on Xamarin.Forms. I wonder why there is so less support for Xamarin.Android.
Anyways, i came across a few questions on SO and tried this :
TestControl.cs
namespace TestApp.CustomControls.Classes
{
public class TestControl : ViewGroup
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
throw new NotImplementedException();
}
public TestControl(Context context, IAttributeSet attrs)
: base(context, attrs)
{
}
}
}
TestControl.xml
<TestApp.CustomControls.Classes.TestControl xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="20dp" android:layout_width="20dp"
android:background="#fff">
In my activity_main.axml file, i have the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="50dp"
android:layout_weight="50dp">
<TestApp.CustomControls.Classes.TestControl android:layout_height="50dp"
android:layout_weight="50dp"/>
</RelativeLayout>
Even though intellisense is able to find TestApp.CustomControls.Classes.TestControl but i don't see anything on the screen. Maybe because i never linked the xml file with the class?(Still now sure how xamarin.android works).
So, what should be my steps to get the custom control working/visible on view?
Views and/or to describe layout parameters of its children, what do you expect to see when it does does not contain any children?<LinearLayout>to the Xml file but didn't result in anything.... Maybe i am missing a lot here. Any guidance?Tile.cs? How does it actually look like? And the way his,Tile.xmllooked....well, how is he supposed to connect the control's code-behind with the xml?