我有这段代码:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;
using System.Collections.Generic;
namespace SayItAndroid{ [Activity (Label = "SayItAndroid", MainLauncher = true)]
public class Activity1 : Activity, TextToSpeech.IOnInitListener
{
int count = 1;
TextToSpeech mTts;
public void OnInit (int status)
{
Console.WriteLine ("Listening to text to speech");
}
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
Intent checkIntent = new Intent();
checkIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData);
StartActivityForResult(checkIntent, 100); // Get our button from the layout resource, // and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate
{
string myText1 = "Did you sleep well?";
string myText2 = "I hope so, because it's time to wake up.";
mTts.Speak(myText1, QueueMode.Add, new Dictionary<string, string>());
mTts.Speak(myText2, QueueMode.Flush, new Dictionary<string, string>());
};
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult (requestCode, resultCode, data);
if(requestCode == 100)
{
mTts = new TextToSpeech(this, this);
}
}
}}
但是在这两个地方我有资源在资源下出现红线错误:
错误1名称&#39;资源&#39;在当前上下文中不存在
我该如何解决?
感谢。
答案 0 :(得分:7)
无法找到资源的原因是10次中的9次,因为资源与您引用它的文件不在同一名称空间中。
如Xamarin所述on this page,项目的默认命名空间用于存储生成的Resource类文件。
如果你的类驻留在另一个命名空间中,那么事情就会中断。
希望能为你解决问题。