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

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.

主站蜘蛛池模板: 和平县| 青铜峡市| 仲巴县| 枣强县| 丁青县| 商城县| 大埔区| 长乐市| 洪洞县| 攀枝花市| 长兴县| 双桥区| 迁西县| 桑植县| 靖远县| 洛阳市| 灵宝市| 县级市| 房产| 如皋市| 临海市| 栾川县| 海口市| 洛隆县| 揭东县| 林周县| 水城县| 浠水县| 双牌县| 庆元县| 黄骅市| 利辛县| 常德市| 兴山县| 万宁市| 上饶市| 时尚| 翁源县| 固阳县| 宜州市| 牡丹江市|