当用户点击ActionBar上的主页按钮时,我想要一个下拉菜单。如下所示: -
我尝试过像这样使用Spinner: -
public override bool OnOptionsItemSelected(Xamarin.ActionbarSherlockBinding.Views.IMenuItem item)
{
// Click events for ActionBar items
switch(item.ItemId)
{
// Home (Top left corner)
case Android.Resource.Id.Home:
var mspinner = new Spinner(this);
ArrayList mSpinnerOptions = new ArrayList();
mSpinnerOptions.Add("Stay");
ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, mSpinnerOptions);
mspinner.Adapter = adapter;
ActionBar.SetCustomView(mspinner);
break;
}
但是当我尝试SetCustomView
时,它会给我一个错误。
Error 3 The best overloaded method match for 'Android.App.ActionBar.SetCustomView(int)' has some invalid arguments
编辑: -
我尝试过类似下面的内容: -
LayoutInflater inflater = LayoutInflater.From(this);
View mCustomeView = inflater.Inflate(Resource.Layout.spinnerlayout, null);
Spinner mspinner = mCustomeView.FindViewById<Spinner>(Resource.Id.home_spinner);
ArrayList mSpinnerOptions = new ArrayList();
mSpinnerOptions.Add("Stay");
ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, mSpinnerOptions);
mspinner.Adapter = adapter;
ActionBar.SetDisplayShowCustomEnabled(true);
ActionBar.SetCustomView(mCustomeView, null);
但仍然得到同样的错误
答案 0 :(得分:0)
我认为你应该替换这句话:
var mspinner = new Spinner(this);
为:
Spinner mspinner = new Spinner(this);
它将告知编译器您正在创建一个Spinner对象。