There is a class which inherits TextView

using Android.App; using Android.Content; using Android.Content.Res; using Android.Runtime; using Android.Text; using Android.Util; using Android.Views; using Android.Views.InputMethods; using Android.Widget; using Android.OS; using Android.Graphics; namespace HelloWorld { class TodoListItemView:TextView { private Paint marginPaint; private Paint linePaint; private int paperColor; private float margin; public TodoListItemView(Context context, IAttributeSet attrs, int ds): base (context, attrs, ds) { init(); } public TodoListItemView(Context context, IAttributeSet attrs) : base(context, attrs) { init(); } private void init() { Resources myResources = Resources; marginPaint = new Paint(PaintFlags.AntiAlias); marginPaint.Color = myResources.GetColor(Resource.Color.notepad_margin); linePaint = new Paint(PaintFlags.AntiAlias); linePaint.Color = myResources.GetColor(Resource.Color.notepad_lines); paperColor = myResources.GetColor(Resource.Color.notepad_paper); margin = myResources.GetDimension(Resource.Dimension.notepad_margin); } protected override void OnDraw(Canvas canvas) { canvas.DrawLine(0, 0, Height, 0, linePaint); canvas.DrawLine(0, Height, Width, Height, linePaint); // НарисуйтС ΠΊΡ€ΠΎΠΌΠΊΡƒ canvas.DrawLine(margin, 0, margin, Height, marginPaint); // ΠŸΠ΅Ρ€Π΅ΠΌΠ΅ΡΡ‚ΠΈΡ‚Π΅ тСкст Π² сторону ΠΎΡ‚ ΠΊΡ€ΠΎΠΌΠΊΠΈ canvas.Save(); canvas.Translate(margin, 0); base.OnDraw(canvas); canvas.Restore(); } } 

}

and there is a todolist_item.xml markup

 <?xml version="1.0" encoding="utf-8"?> <TodoListItemView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:scrollbars="vertical" android:textColor="@color/notepad_text" android:fadingEdge="vertical" /> 

I have specified TodoListItemView, but with this name it does not work, an error occurs when opening the markup. There is an example in Java, since there are packages there, everything is clear

 <?xml version="1.0" encoding="utf-8"?> <com.paad.todolist.TodoListItemView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:scrollbars="vertical" android:textColor="@color/notepad_text" android:fadingEdge="vertical" /> 

What name should I give?

  • I started in the android emulator after I set the correct Namespace control: - <MyNameSpace.TestTextView - ShockWave

1 answer 1

In the layout, it was displayed immediately. I started in the android emulator after I installed the correct Namespace control: -

 <MyNameSpace.TestTextView 

Sources:

 class TestTextView:TextView { [Register (".ctor", "(Landroid/content/Context;Landroid/util/AttributeSet; I) V", "")] public TestTextView(Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle) { Text = "TEST TEST TEST"; } } // *************************************************** <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff96aa85"> <Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="fill_parent" android:layout_height="52.0dp" android:id="@+id/editText1" android:layout_marginBottom="0.0dp" /> <MyNameSpace.TestTextView android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/TestText1" android:layout_marginBottom="0.0dp" /> </LinearLayout> 
  • Imports: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Android.Content.Res; using Android.Graphics; using Android.Graphics.Drawables; using Android.Text; using Android.Text.Method; using Android.Text.Style; using Android.Text.Util; using Android.Util; using Android.Views.InputMethods; using Java.Interop; using Java.Lang; - ShockWave
  • also does not start - Qnex
  • Where is the exception? - ShockWave
  • unfortunately has stopped - Qnex
  • If you copy to todolist_item.xml, everything works <TextView xmlns: android = " schemas.android.com/apk/res/android " android: id = "@ android: id / text1" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: textAppearance = "? android: attr / textAppearanceLarge" android: gravity = "center_vertical" android: paddingLeft = "6dip" android: minHeight = "? android: attr / listPreferredItemHeight" /> - Qnex