0

I am trying to implement a TabLayout in Xamarin Android.

However when I try to construct a TabLayout I get the following exception

Java.Lang.IllegalArgumentException: You need to use a Theme.AppCompat them (or descendant) with the design library.

I have tried this with the TabLayout in an .axml layout but when I inflate it I get the exception.

I also tried taking it out of the .axml layout file and programmatically adding it to the view after I inflated. In this case I get the exception directly after calling

var tabLayout = new TabLayout(Application.Context);

I have also set the theme to Theme.AppCompat in the AndroidManifest file

I have spent two days on this and need some help, it would be useful if someone had a very simple working example they could share.

I am using Xamarin and MvvmCross.

rideintothesun
  • 1,628
  • 2
  • 12
  • 29
  • Possible duplicate of [You need to use a Theme.AppCompat theme (or descendant) with this activity](http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity) – SushiHangover Feb 07 '17 at 17:02
  • No, none of these have worked for me unfortunately. – rideintothesun Feb 07 '17 at 17:17

2 Answers2

0

You mention you have added a Theme to your AndroidManifest.xml. Depending on what node you assign it to, it might get overwritten on build time, by what is specified in the [Activity] attribute on your Activity.

Normally in Xamarin.Android you would add it to the [Android] attribute instead of manually editing the manifest.

You can check your resulting manifest in obj\android and see whether it still contains the Theme you have set. Otherwise add it like so:

[Activity(Label = "MyActivity", Theme = "@style/MyTheme")]
public class MyActivity : AppCompatActivity

This way it will get added correctly on build time to the manifest.

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
  • I don't know what happened but I put the tabLayout back into the .axml file and gave it a style of Theme.AppCompat and it now inflates. Not quite sure why it's working but it is working. – rideintothesun Feb 07 '17 at 17:56
0

I don't know what happened but I put the tabLayout back into the .axml file and gave it a style of Theme.AppCompat and it now inflates. Not quite sure why it's working but it is working.

rideintothesun
  • 1,628
  • 2
  • 12
  • 29