Custom Drawable causes Inflation Exception

22 views Asked by At

I am attempting to create a Custom Drawable, but it is causing a Java.Lang.RuntimeException and Error inflating class android.widget.GridLayout when I try to use it. Here is the code:

using Android.App;
using Android.Graphics;
using Android.Graphics.Drawables;

namespace PointSaladScorekeepingAssistant
{
    public class TextDrawable : Drawable
    {
        private Paint TextPaint;

        public TextDrawable()
        {
            this.TextPaint = new Paint() { Color = Application.Context.Resources.GetColor(Resource.Color.Black, null), TextAlign = Paint.Align.Left, TextSize = 48 };
            this.TextPaint.SetTypeface(Application.Context.Resources.GetFont(Resource.Font.HorsGarter));
        }

        public override int Opacity { get { return 255; } }

        public override void Draw(Canvas canvas)
        {
            canvas.DrawColor(Application.Context.Resources.GetColor(Resource.Color.Orange, null));
            Rect bounds = new Rect();
            this.TextPaint.GetTextBounds("CABBAGE", 0, 7, bounds);
            canvas.DrawText("CABBAGE", 0, 0, this.TextPaint);
        }

        public override void SetAlpha(int alpha) { this.TextPaint.Alpha = alpha; }

        public override void SetColorFilter(ColorFilter colorFilter) { this.TextPaint.SetColorFilter(colorFilter); }
    }
}

What is the problem?

0

There are 0 answers