简体   繁体   中英

Dropdown Menu on Home button click ActionBarSherlock xamarin

I want a dropdown menu when the user clicks the home button on the ActionBar. Something like below:-

在此处输入图片说明

I have tried using a Spinner like so:-

    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;
}

But it gives me an error when I try to SetCustomView .

Error   3   The best overloaded method match for 'Android.App.ActionBar.SetCustomView(int)' has some invalid arguments

Edit:-

I tried something like below:-

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);

But still get the same error

I think you should replace this statement:

var  mspinner = new Spinner(this);

to:

Spinner  mspinner = new Spinner(this);

It's going to inform the compiler that you are creating a Spinner object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM