Search code examples
xamarinxamarin.formscustom-renderer

The type or namespace name 'Graphics' does not exist in the namespace 'Project.Android'


I am working on a Xamarin.Forms application, In which I have added a custom renderer to set the background of native edit text. Following Code shows error. var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());


Solution

  • The issue is that your application uses the namespace Project.Android and the type system will think Android.Grapics.Drawables.Shapes.RectShape belongs in Project.Android.

    You some options:

    1. Change your namespace for the project and in all your classes
    2. Prefix Android.Graphics.Drawables.Shapes.RectShape with global:: like: global::Android.Graphics.Drawables.Shapes.RectShape
    3. Add a using at the top of the file telling where RectShape comes from: using RectShape = Android.Graphics.Drawables.Shapes.RectShape and just use new RectShape()