警告:方法X已过时;& #39;deprecated'"的意思

本文关键字:deprecated 意思 quot 警告 方法 过时 | 更新日期: 2023-09-27 18:03:42

演讲在我的真实设备上运行良好。

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Speech.Tts;
namespace App7
{
    [Activity(Label = "App7", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity, TextToSpeech.IOnInitListener
    {
        public TextToSpeech SpeechText
        {
            get;
            set;
        }
        int count = 1;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // create text to speech object to use synthesize and speak functions.
            // first parameter: context
            // second parameter: object implemeting TextToSpeech.IOnInitListener
            this.SpeechText = new TextToSpeech(this, this);
            Button testButton = FindViewById<Button>(Resource.Id.button1);
            testButton.Click += delegate
            {
                this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);
            };
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
        public void OnInit(OperationResult status)
        {
            // here you can setup language settings
            if (status.Equals(OperationResult.Success))
                Toast.MakeText(this, "Text To Speech Succeed!", ToastLength.Long).Show();
            else
                Toast.MakeText(this, "Text To Speech Fail", ToastLength.Long).Show();
        }
    }
}

警告在这一行:

this.SpeechText.Speak("Hello World, You shall not pass", QueueMode.Flush, null);

在这行下面有一条绿线,警告信息是:

警告1 'Android.Speech.Tts.TextToSpeech. '(字符串,Android.Speech.Tts说话。QueueMode, system . collections . generic . dictionary)'已过时:'deprecated'

试着谷歌没有找到任何东西。我可以忽略它,但我想知道它是什么意思?

警告:方法X已过时;& #39;deprecated'"的意思

这意味着这种重载在Xamarin中已被弃用(因为Google在API级别21时将其标记为已弃用)。

使用其他两个未弃用的重载(1,2),如果警告困扰您并且您的目标API级别允许它,或者直接忽略警告。