Xamarin.Forms and Android Design Support Library

TedRogersTedRogers USMember ✭✭✭✭

I am trying to create a TabLayout control in a custom renderer. I have added the Android Design Support Library package and am able to create the TabLayout control in my custom renderer if I use the AppCompat theme, but not otherwise. However, when I use the AppCompat theme, the app throws an exception later on in the launch process.. How can I use widgets from the Design Support Library in a Xamarin.Forms app?


[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarHomeAsUp (Android.App.ActionBar) <IL 0x0001f, 0x000ad>
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.HideActionBar () <IL 0x0000d, 0x0005f>
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () <IL 0x000a8, 0x0033f>
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page) <IL 0x000c0, 0x003e3>
[MonoDroid] at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page) <IL 0x000be, 0x00413>
[MonoDroid] at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () <IL 0x0000c, 0x00047>
[MonoDroid] at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application) <IL 0x0002e, 0x00153>
[MonoDroid] at MySecondFormsApp.Droid.MainActivity.OnCreate (Android.OS.Bundle) [0x00015] in /Users/tedrogers/Documents/Xamarin/MySecondFormsApp/Droid/MainActivity.cs:22
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707


  • MichaelPhamMichaelPham USMember

    Unfortunately, Forms doesn't really support the Design Support library easily. There are quite a few things you need to do in order to support the AppCompat themes. I started a project to help alleviate some of these issues, but it's still not 100% (and I don't know that it can be without support from Xamarin) complete support for all things Material Design.

    Also, you can't use the NoActionBar themes with Forms regardless of which theme you choose. It just comes down to Forms expecting there to always have an ActionBar, unfortunately. And it's hard to write a custom FormsApplicationActivity that doesn't require it due to the visibility of the Platform class without tons of Reflection code (it's doable though, as I've been experimenting with it).

    Please see this GitHub project.

    Using the project and/or NuGet packages should at least get you towards using the TabLayout widget, though I haven't tried this yet myself.

  • TedRogersTedRogers USMember ✭✭✭✭

    @MichaelPham Thanks for the info. That was what I was afraid of. I was evaluating using Xamarin.Forms for a project I was about to start but I think I'm going to stick with good ole Xamrin.iOS and Xamarin.Android.


  • stvansolanostvansolano UMInsider, University ✭✭✭
    edited July 2015

    hey @TedRogers I was having the same issue trying with AppCompat before, then I ffollow up this thread but I haven't tried it.

    Hope it helps for anyone considering this approach. Even better, if t works for you let me know :)

Sign In or Register to comment.