官术网_书友最值得收藏!

Setting up IoC with Android

Now for the IoC implementation. It works exactly the same as iOS; let's add the Android module:

    public class DroidModule : IModule 
    { 
        public void Register(ContainerBuilder builer) 
        { 
            builer.RegisterType<TextToSpeechDroid> ().As<ITextToSpeech> ().SingleInstance (); 
        } 
    } 

Easy, right?

Now we have to set up the IoC container in our MainActivity.cs class; simply copy the iOS function in the AppDelegate file called initIoC and paste this into the MainActivity class, replace the instantiation of the iOSModule with your DroidModule, then simply add the function call after the initialization of Xamarin.Forms:

protected override void OnCreate (Bundle bundle) 
        { 
            base.OnCreate (bundle); 
 
            global::Xamarin.Forms.Forms.Init (this, bundle); 
 
            InitIoC (); 
 
            LoadApplication (new App ()); 
        } 
 
        private void InitIoC() 
        { 
            IoC.CreateContainer (); 
            IoC.RegisterModule (new DroidModule()); 
            IoC.RegisterModule (new PCLModule()); 
            IoC.StartContainer (); 
        } 

Note

You may have issues trying to get the speech to work on Android. One thing you may need to set up first is within Settings | Controls | Text-to-Speech options. Here is where you will have to install voice data if the default has not already been installed. If you run the app and no speech occurs, you will have to configure the voice data.

That's all for Android, now try running the app and hear some speech.

主站蜘蛛池模板: 南乐县| 崇阳县| 利川市| 色达县| 常熟市| 元江| 建平县| 揭东县| 故城县| 新野县| 香河县| 丽水市| 长顺县| 抚顺市| 奉节县| 大安市| 广饶县| 四川省| 宜章县| 宝兴县| 日土县| 蒲城县| 观塘区| 巴楚县| 云林县| 贞丰县| 剑河县| 延津县| 荣成市| 和田县| 扶风县| 泰顺县| 汉沽区| 阳城县| 尖扎县| 虞城县| 林芝县| 敦化市| 阜新市| 文昌市| 玉屏|