命名空间“Project.Android”中不存在类型或命名空间名称“Graphics”

Suy*_*ash 0 custom-renderer xamarin xamarin.forms

我正在开发一个 Xamarin.Forms 应用程序,我在其中添加了一个自定义渲染器来设置本机编辑文本的背景。以下代码显示错误。 var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());

Che*_*ron 5

问题是您的应用程序使用命名空间Project.Android,类型系统会认为Android.Grapics.Drawables.Shapes.RectShape属于Project.Android.

你有一些选择:

  1. 更改项目和所有类的命名空间
  2. 前缀Android.Graphics.Drawables.Shapes.RectShapeglobal::这样的:global::Android.Graphics.Drawables.Shapes.RectShape
  3. 在文件顶部添加一个 using 告诉RectShape从哪里来:using RectShape = Android.Graphics.Drawables.Shapes.RectShape然后使用new RectShape()