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?