Reputation: 752
I'm having a hard time using ActionBarActivity in my app, as I am unable to import it. I tried adding Android Support Library 4,7,13 and 17...
Nr.7, 13 and 17 doesn't work, because "Some required packages are not referenced by the project". I haven't figured out what that even means.
Nr.4 doesn't work, because "The type or namespace name 'ActionBarActivity' could not be found (are you missing a using directive or an assembly reference?) C:\progge\Apper\AkvaApp\AkvaApp\AkvaApp\Browser.cs"... even though ActionBarActivity is supposed to be included in the component.
I have built and rebuilt, again and again.
Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Support.V4;
using Xamarin;
namespace AkvaApp
{
[Activity(Label = "Browser")]
public class Browser : ActionBarActivity, ActionBar.ITabListener
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SupportRequestWindowFeature(WindowCompat.FeatureActionBar);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
SetContentView(Resource.Layout.BrowserLayout);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
ActionBar.Tab tab = ActionBar.NewTab();
tab.SetText(Resources.GetString(Resource.String.SearchTabText));
tab.TabSelected += (sender, args) =>
{
Android.Util.Log.Info(this.Class.Name, "this is an info message");
Android.Util.Log.Warn(this.Class.Name, "this is a warning message");
Android.Util.Log.Error(this.Class.Name, "this is an error message");
};
}
public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction ft)
{
throw new NotImplementedException();
}
public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
{
throw new NotImplementedException();
}
public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction ft)
{
throw new NotImplementedException();
}
}
}
Whyy?
Upvotes: 2
Views: 5541
Reputation: 752
I still haven't managed to get it working in Visual Studio, but I did manage in Xamarin Studio. Adding Support Library v7 in Visual Studio did not help at all, but adding it in Xamarin Studio fixed it.
For Xamarin Studio: Right-click the project (not the solution), click Add -> Add NuGet Packages, search for "support library v7", check off the one called AppCompat, and click Add Packages. Then in the class that requires this library, add "using Android.Support.V7;"
Upvotes: 3
Reputation: 13176
ActionBarActivity is part of the Support Library v7 AppCompat as mentioned by Martijn
https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
Android.App.ActionBar
with ActionBar
as you are trying to access this from a static context.deprecated
and you should use other patterns instead(http://developer.android.com/design/patterns/navigation.html)Upvotes: 2
Reputation: 3559
You need to add the nuget package to Support Library v7 AppCompat to use the ActionBarActivity. James Montemagno of Xamarin explains this in: http://blog.xamarin.com/android-support-library-v7-hello-actionbarcompat/
If you want to know why "Some required packages are not referenced by the project" is coming, you should look into the package console to see what the actual error message is about.
Upvotes: 1