- 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.
- Mastering Visual Studio 2017
- 大學計算機應用基礎實踐教程
- 青少年美育趣味課堂:XMind思維導圖制作
- Linux網(wǎng)絡程序設計:基于龍芯平臺
- concrete5 Cookbook
- Apache Mahout Clustering Designs
- 從零開始學C語言
- Python機器學習之金融風險管理
- Apache Camel Developer's Cookbook
- Learning iOS Security
- AI自動化測試:技術原理、平臺搭建與工程實踐
- SSH框架企業(yè)級應用實戰(zhàn)
- Java Web開發(fā)基礎與案例教程
- HTML并不簡單:Web前端開發(fā)精進秘籍
- Computer Vision with Python 3