【问题标题】:Xamarin Forms Android error CS0117: 'Resource.Drawable' does not contain a definition for "...."Xamarin Forms Android 错误 CS0117:“Resource.Drawable”不包含“....”的定义
【发布时间】:2020-06-29 18:05:03
【问题描述】:

我正在尝试在 Visual Studio 2019 上的 Xamarin Forms Android 中使用视频构建启动画面。Xamarin Forms 版本 4.7.0.968。我正在尝试打开位于 Resources/drawable 文件夹中的视频文件“Intro.mp4”。视频的构建操作设置为“AndroidAsset”,并且在 Drawable 类中的 Resource.designer.cs 中已经包含一个 id:

这里是我引用文件的地方:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{        
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);

        StartService(new Android.Content.Intent(this, typeof(AudioService)));

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

        SetContentView(Resource.Layout.Splash);
        var videoView = FindViewById<VideoView>(Resource.Id.splashVideo);

        string videoPath = $"android.resource://{Application.PackageName}/{Resource.Drawable.Intro}";
        videoView.SetVideoPath(videoPath);
        videoView.Start();            

        LoadApplication(new App());
    }

当我构建项目时,我收到此错误:“错误 CS0117:'Resource.Drawable' 不包含 'Intro' 的定义”。我尝试了在论坛中找到的几个建议,删除 obj 和 bin 文件夹,重新启动 Visual Studio,重新启动我的电脑,卸载 Xamarin 并重新安装它,在 NuGet 包管理器中回滚到以前的 Xamarin 包,但没有任何帮助。我不确定这是 Xamarin 错误还是我的代码有问题。任何帮助将不胜感激。

【问题讨论】:

  • 一个资产和一个资源不是一回事——如果你想要一个资源,构建动作应该是Android Resource
  • 就是这样!您想将此添加为答案,以便我给您加分吗?

标签: android xamarin.forms visual-studio-2019 splash-screen


【解决方案1】:

Asset 和 Resource 不是一回事——如果你想要一个资源,build action 应该是 Android Resource

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2011-02-18
    • 1970-01-01
    • 2018-09-29
    相关资源
    最近更新 更多