We have recently been tasked to build an app for one of our clients. So I am going to provide you with a basic outline of creating a Xamarin android app. Why Xamarin and not straight up android you ask? Here at QuayTech one of our specialisms is .Net and because .Net is a Microsoft technology they like to use either C# or Visual basic as a programming language. So we have chosen to use Xamarin as it is a framework written in C# that will allow us to write apps in C# as opposed to Java which standard Android apps are written in.
To begin open Microsoft Visual Studio, select New Project and choose Android on the left hand side and a blank android app as the project type. Note: As a pre-requisite you will need to have Xamarin installed for your visual studio (). You can then name your app and choose the location to save the app to.
I’m going to talk to you about the basic overview layout of the Xamarin android project. The Assets folder is where you store assets that aren’t images for example database files. Inside the resources folder the drawable section is where you can store any images you have that are not icons. The various mipmap folders are designed for storing different icons and splashscreen images at different resolutions as outlined in this blog here. Inside the layout folder are .axml files. These are essentially different views, if you double click on you’ll see that it opens a designer in visual studio as I’ll demonstrate in a minute. Inside the values folder, the Strings.xml folder is used to store constants that are used throughout your app, for example the app name, a company slogan, etc i.e. things that may need updating throughout the app. The last important part of the layout is the MainActivity.cs file at the bottom. As you can see the convention here is that the activity matches to a designated layout file. The activity file essentially acts as your code behind for the layout.
After double clicking on a .axml file you are presented with this screen. In the centre you can see the view that you are currently working with and the left is a toolbox which houses different components. As you can see in the bottom left of the centre screen you can switch between the design and the source of the view. It is now a case of dragging and dropping your components onto the page and editing the properties for each.
As I said earlier the activity files are designed to act as the code behind for the views. For example this is the one for the Main layout which is created by default. At the top we can see that the title for the page is set, and we have told the application that this is the first page that we want to load by the MainLauncher flag being set. Inside the ‘oncreate’ method we can see that we have told the activity to link to the Main layout that we spoke about earlier.
So there you have it a basic overview of the Xamarin Android project. Now it’s time for you to go off and experiment with hopefully this very helpful tutorial/overview.