Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ActionBarSherlock in Mono Android

I am trying to implement the ActionBar in a Mono Android application. Could someone provide me steps to including the ActionBar project in my solution? I have seen the sample projected provided at this url https://github.com/xamarin/monodroid-samples/tree/master/ActionBarSherlock

Do I have to simply add a reference of the ActionBarSherlock project in that sample? When I attempt to add a reference to that project I get many errors such as "Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Holo.Widget.ActionBar.Menu'." in file abs_styles.xml

Has anyone else successfully added ActionBarSherlock to a Mono Android Project? Could you please provide me steps to get a simple example working?

like image 977
kevskree Avatar asked Dec 11 '22 18:12

kevskree


1 Answers

Ok, this is how I got it working...

  1. Open up the sample project and build just the 'ActionBarSherlock' project on Release mode. Make sure that the minimum target android version is 4.0.3 (required)

  2. Take the dll and reference it in your project. I have found that you can get it to compile fine if your project has a minimum android version of 2.2 - I found that if you used profile version 2.1 it doesn't work, but that just might of been my app. Maybe your minimum version is too low? I also set my 'target' android to be the latest... I don't know if this helps too.

  3. The reason I say to reference the dll instead of the project is that you will get the correct intellisense. Otherwise as you can see in the example project it does not (Makes working on it a pain!).

  4. Make sure you have a reference to the v4 support lib in your project (Mono.Android.Support.v4)

  5. The final step is that need to change your default theme to use a Sherlock theme. (see xml below for example)

  6. Use the ActionbarSherlock.* namespaces when adding Actionbars etc...

Example manifest after adding ActionbarSherlock:

<manifest ...>
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
    <application android:label="IDNT" android:theme="@style/Theme.Sherlock.Light.DarkActionBar" android:icon="@drawable/Icon">
    </application>
</manifest>

BEWARE: There is a small issue with all this... If your project has a minimum version of under 3.0 (ie 2.2 as per my example) and you compile with linking (ie SDK assemblies only) you will get an error 'Mono.Cecil.ResolutionException: Failed to resolve Android.Database.IDatabaseErrorHandler'. I am currently sending support messages about this to Xamarin and will edit this post once I work out a fix.

EDIT: To fix the issue I have mentioned above make sure that the project options -> Application -> Minimum Android to target option is at LEAST 4.0.3. Your minSdkVersion can still be 7/8 or whatever so it will still run in older android versions. It also means you have to be careful you dont code in stuff that is for higher versions.

like image 110
Felix Avatar answered Jan 05 '23 16:01

Felix