【发布时间】:2014-07-25 08:59:28
【问题描述】:
我在我的应用程序中使用了 ActionBar。我做了这样的事情:-
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);
但我收到如下编译错误:-
A object reference is required for the non-static field, method, or property 'Android.Support.V7.App.ActionBar.SetDisplayHomeAsUpEnabled(bool)'
如何创建 ActionBar 的实例,因为它是一个抽象类?
编辑:-
使用 waquaslam 的解决方案,我这样做了:-
public class Homescreen : ActionBarActivity
{
private DrawerLayout _drawer;
private MyActionBarDrawerToggle _drawerToggle;
private ListView _drawerList;
private static ActionBar ActionBar ;
private string _drawerTitle;
private string _title;
private string[] _planetTitles;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SupportRequestWindowFeature(WindowCompat.FeatureActionBar);
SetContentView(Resource.Layout.homescreen);
_title = _drawerTitle = Title;
_planetTitles = Resources.GetStringArray(Resource.Array.TitlesArray);
_drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
_drawerList = FindViewById<ListView>(Resource.Id.left_drawer);
_drawer.SetDrawerShadow(Resource.Drawable.drawer_shadow_dark, (int)GravityFlags.Left);
_drawerList.Adapter = new ArrayAdapter<string>(this,
Resource.Layout.drawerlistitem, _planetTitles);
_drawerList.ItemClick += (sender, args) => SelectItem(args.Position);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
SupportActionBar.SetHomeButtonEnabled(true);
//DrawerToggle is the animation that happens with the indicator next to the
//ActionBar icon.
_drawerToggle = new MyActionBarDrawerToggle(this, _drawer,
Resource.Drawable.ic_drawer_light,
Resource.String.DrawerOpen,
Resource.String.DrawerClose);
//You can alternatively use _drawer.DrawerClosed here
_drawerToggle.DrawerClosed += delegate
{
ActionBar.Title = _title;
//InvalidateOptionsMenu();
};
//You can alternatively use _drawer.DrawerOpened here
_drawerToggle.DrawerOpened += delegate
{
ActionBar.Title = _drawerTitle;
// InvalidateOptionsMenu();
};
_drawer.SetDrawerListener(_drawerToggle);
if (null == savedInstanceState)
SelectItem(0);
}
现在我收到了NoClassDefinitionFoundError。
【问题讨论】:
标签: c# android xamarin instance abstract-class