James Montemagno
James Montemagno

Live, Love, Bike, and Code.

Live, Love, Bike, and Code

Share


Tags


Enhanced Xamarin.Android Designer with Tools Attributes

The announcement of Android L Developer Preview support for Xamarin.Android developers brings tons of goodies to start playing around with, but did you know that there has been several updates to the Android designer as well? If you look through the release notes of Xamarin Studio 5.3 you will several enhancements such as the new Android L & Wear themes and devices, but also support for Action Bar menu icons and navigation style via the menu and actionBarNavMode XML attributes. More information on those attributes can be found at http://tools.android.com/tech-docs/tools-attributes#TOC-tools:menu. So, let’s take a look at these new features in the Alpha Channel.

Tools XMLNS

To take advantage of any of the features you will need to add this attribute to your root node in your layout:
 xmlns:tools="http://schemas.android.com/tools"

So your layout might look something like this:





Now we can take advantage of the tools and other attributes and add them onto our root node.

Menu

Normally your menu’s live completely separate away from your layouts, however the tools attributes allow you to get a preview right in the designer. First we will want to add the tools attribute:
tools:menu="menu_name"

Notice that we don’t use any @menu or anything like this. It is just referencing the name in the Resource/Menu folder. This will give us a nice preview:

Navigation Style

Additionally, you might be using tabs or a spinner as part of your navigation in your ActionBar and you can now visualize this with another attribute:
tools:actionBarNavMode="tabs"

The actionBarNavMode can be set to tabs, list, or standard. I actually use a list navigation in My StepCounter, so this is great to be able to visualize:


That is just the beginning as Jérémie Laval has hinted at some more awesome updates coming soon:

Issues with Menu?

If you are having issues with the tools:menu property you might need to remove the Unicode BOM from your xml file. This is just a side effect currently of how the xml files are generated. Once you delete the 3 invisible bytes you will be able to browse things just fine. It is relatively easy and quick to do this. First make sure the file is CLOSED inside of Xamarin Studio. Then you will want to say open in HEX Editor:

Now simply delete the first 3 bytes on the right hand side that:

Alright you are all set now :)

Copyright © James Montemagno 2014 All rights reserved. Privacy Policy

View Comments