0

Iam using A ActionBar in my app. I have done something like so:-

ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);

But I get a compilation error like:-

A object reference is required for the non-static field, method, or property 'Android.Support.V7.App.ActionBar.SetDisplayHomeAsUpEnabled(bool)'

What could be the problem/? Iam developing android in C# for the first time. Any suggestions will be helpful.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3146095
  • 419
  • 2
  • 7
  • 25
  • It seems `SetDisplayHomeAsUpEnabled` is instance method, but you're accessing it as it were static. You need to create an instance of `ActionBar` then call `actionBarInstance.SetDisplayHomeAsUpEnabled`. Refer suggested duplicate for more info. – Sriram Sakthivel Jul 25 '14 at 07:51
  • @SriramSakthivel ActionBar is a abstract class. How do I create its instance – user3146095 Jul 25 '14 at 08:05
  • You need to create an instance of it's sub class, Find it otherwise ask a new that's because that's a new question indeed.. – Sriram Sakthivel Jul 25 '14 at 08:06
  • First of all, your Activity has to be derived from either ActionBarActivity or one of it's sub-classes. Then you'll see the ActionBar property. If you're using AppCompat, then you'll need to use the SupportActionBar property. – Kiliman Jul 25 '14 at 15:04
  • @SriramSakthivel ActionBar is the name of a class, as well as a property on the class ActionBarActivity. If OP did not derive from ActionBarActivity, then that property wouldn't exist and the compiler would treat it as if he was accessing a static property of class ActiionBar. That's where the error message is coming from. He does not need to create an instance of ActionBar. – Kiliman Jul 25 '14 at 15:58

0 Answers0