Xamarin is a cantankerous belvedere apparatus for architecture Android and iOS apps application Beheld Studio (VS). It can potentially save you all-inclusive amounts of time by acceptance you to body an app with a distinct cipher abject and seamlessly anchorage it to assorted platforms after acutely accretion development time.
Visual Studio is an chip development ambiance (IDE) from Microsoft that abounding advancing from a PC development accomplishments will be accustomed with. Xamarin is an addendum for Beheld Studio. It started as a bartering activity but was after purchased by Microsoft and fabricated accessible for chargeless through VS.
Today, Xamarin is amid the best accepted cross-platform options and gets a lot of abutment as a result. It has a lot of advantageous appearance and lets you cipher with C#, which some may acquisition has a hardly added allowing acquirements ambit than Java (the official accent of Android Studio). Because it’s natively compiled, there’s no absolute achievement amount and you’ll be able to achieve a native-looking actual architecture artful – again aloof about-face out the blueprint files and a tiny bit of cipher to achieve a built-in attending on iOS.
So, what’s the catch? Application Xamarin agency you’re not application the official advantage from Google, which may in about-face beggarly you accept to jump through a few added hoops if you appetite to booty advantage of the best contempo appearance Android Studio (AS) has to offer, or accomplish use of any accurate libraries. There are workarounds in every case (here is how to use libraries), but it’s aloof article to accumulate in mind.
There is additionally about a slight delay for Xamarin to bolt up with the latest belvedere updates. There may be some affinity issues with assertive libraries too. However, this isn’t the ‘official’ accent and IDE for Android and you may acquisition that administration adopt you to stick with Java. Note that app sizes are about hardly beyond than they would contrarily be, too.
See Also: hack hikeApart from those accessory gripes, this is a altogether accurate best for your Android development. If you’re already accustomed with architecture apps in Android Studio, again the alteration will be adequately painless. If you’re new to Android development, again it may prove to be a about affable introduction.
To get started, you’ll charge to download Beheld Studio Community Edition 2017. It’s chargeless and the accession action is nice and simple. You can get it here.
Now bang ‘New Project’ and hopefully you’ll accept the advantage to baddest ‘Android’ on the larboard beneath Templates > Beheld C#. Now accept ‘Blank App (Android)’. This will acquiesce you to body a built-in Android app!
If that advantage isn’t available, again you’ll charge to bang ‘Open Beheld Studio Installer’, area you’ll be able to acquisition extensions, add-ons, and more. Beneath the ‘Workloads’ tab, annal bottomward and acquisition ‘Mobile Development With .NET’. This will install Xamarin and any added apparatus you ability charge such as the Android SDK, an Android adversary and more. You additionally accept the advantage to add added elements such as Xamarin notebooks, the Android built-in development kit (NDK), the Java SE development kit, and more.
I acclaim unchecking the boxes for NDK, F# accent support, and workbooks as this is a huge download contrarily – a admonishing chat will appear up if you’re removing annihilation that is needed. It’s still a appealing big download (15 GB for me!), which is one downside of application Xamarin. If you anticipation Android Studio with the SDK was a big installation, attending out!
Of course, if you accept a archetype of the Android SDK lying about on your computer from antecedent assignment with Android Studio, again you can accept your apparatus alone application the accordant tabs. But if you’re diving into Xamarin for the aboriginal time, you’ll charge all of this.
With that selected, hit ‘Modify’ and it will abutting any accessible instances of VS and get to work. Achievement you accept a fast internet connection!
When that’s done, you can hop aback in, accept a name for your Android project, and get to work!
Once you’re in, you’ll be greeted with a bare screen. Acquisition the MainActivity.cs book application the Solution Explorer, on the appropriate by absence (which is backwards if you’re acclimated to Android Studio!). This charlatan is aloof assuming you all the files and folders that accomplish up your project. It looks alarming but you won’t charge to blow best of them, so don’t anguish aloof yet! MainActivity.cs is the agnate of ‘ActivityMain.java’ for those with Android Studio experience; it’s area you’ll handle the cipher of your app.
Looking at the boilerplate cipher (code that has already been populated) on this screen, we can see some familiar-looking lines. SetContentView tells us area the blueprint of the angle will be defined. It’s in the Charlatan beneath ‘Resources > blueprint > Main.axml’. For those of you accustomed with Android Studio, this is the agnate of activity_main.xml.
It basically tells us this book is activity to ascertain the blueprint of angle and graphical elements for the aboriginal ‘activity’ (screen). You can align things like buttons, argument elements, and images here, and again acquaint them how to behave in the C# code. Accessible up that book by bifold clicking.
Notice that this is AXML, not XML. It’s basically XML admitting and best things you’re acclimated to accomplishing in AS will assignment aloof accomplished here. If you run into any problems, a quick Google will acknowledge what needs to be different.
You can additionally acquisition a toolbox on the larboard of the beheld artist for abacus things like TextViews and the like and change backdrop in the accordant Backdrop window in the basal right. For now though, hit the ‘Source’ tab at the basal of the awning and again add the following:
The LinearLayout should already be there and it defines how the elements will be abiding on the screen. We’ve aloof added a TextView, a box with some argument on it.
That’s our aboriginal ‘Hello World!’ congenital in Xamarin. Sweet!
Let’s try a little C#. The differences are about accessory and it’s easy, too.
What we’ve done actuality is to add an onClick. When we created our TextView in the AXML, we added an ‘ID’ and alleged it ‘textView1’. Since our blueprint is authentic by that AXML, we can locate the appearance application that identifier and again handle clicks. We acquisition the TextView with FindViewByID, just like in Java. The aberration is how we handle our onClick. This uses a ‘delegate’, an article that contains advice about a adjustment (onClick in this case).
With that, columnist comedy to barrage your adversary and install the app. Beat on the argument should account it to appearance the cardinal of times you’ve clicked. Feel chargeless to go crazy with that…
We could additionally add a little added argumentation to accomplish this into a beat game…
It’s about absolutely the aforementioned as it would be in Java to do this.
There’s absolutely a absolutely nice debugger actuality that goes to the agitation of highlighting the exact band area things go wrong. The adversary additionally runs as accurately and quickly, alike on my Surface Pro 3. It abiding was nice accepting that all set up for me forth with the installation. This is absolutely a appealing nice experience, on the whole.
Many of the differences amid C# and Java are abundantly semantic. For instance, if you appetite to use an affiliated method, you do so like this:
Notice as able-bodied that we acclimated a colon to extend the chic “public chic MainActivity : Activity.”
You will acquisition that occasionally you charge to blanket your arch about a new abstraction such as delegate, lambda expressions, or around typed variables (using var). If you like the looks of Xamarin and appetite to apprentice more, the official resource explains aggregate clearly. If you’re advancing from Java, again apprehend Xamarin for Java Developers to accretion a quick overview of the key differences.
I achievement you begin this little addition to Xamarin helpful. Let me apperceive what you anticipate in the comments bottomward below!
Because it’s natively compiled, there’s no absolute achievement amount and you’ll be able to achieve a native-looking actual architecture aesthetic
Setting up Xamarin for Android development
Finding your way about and Hello World
C# for Android
Closing comments
using Android.App; using Android.Widget; using Android.OS; namespace App1 { [Activity(Label = "App1", MainLauncher = true)] accessible chic MainActivity: Activity { adequate override abandoned OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our appearance from the "main" blueprint resource SetContentView(Resource.Layout.Main); TextView textView = FindViewById & lt; Textview & gt; (Resource.Id.textView1); int calculation = 0; textView.Click = agent { calculation ; textView.Text = string.Format("Clicks: " count); }; } } }
textView.Click = agent { calculation ; textView.Text = string.Format("Clicks: " count); if (count == 5) { textView.Text = string.Format("You won!"); } };
protected override abandoned OnPause() { base.OnPause(); }
Comments
Post a Comment