- Xamarin Blueprints
- Michael Williams
- 205字
- 2021-07-08 11:48:24
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.
- 造個小程序:與微信一起干件正經(jīng)事兒
- 劍指JVM:虛擬機實踐與性能調(diào)優(yōu)
- Magento 2 Theme Design(Second Edition)
- Learning SQLite for iOS
- 程序員考試案例梳理、真題透解與強化訓練
- Java 11 Cookbook
- Access 2010數(shù)據(jù)庫應用技術(第2版)
- Java網(wǎng)絡編程實戰(zhàn)
- TMS320LF240x芯片原理、設計及應用
- 響應式Web設計:HTML5和CSS3實戰(zhàn)(第2版)
- Java Web開發(fā)實例大全(基礎卷) (軟件工程師開發(fā)大系)
- Java EE程序設計與開發(fā)實踐教程
- Linux Networking Cookbook
- Hands-On Data Visualization with Bokeh
- 開發(fā)者測試