Skip to content

Action Menu

Federico Navarrete edited this page Jul 1, 2019 · 2 revisions

Step 1. Create XML menu resource file.

Create main.xml file in Resources folder

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:title="Item 1"/>
	<item android:title="Item 2"/>
	<item android:title="Item 3"/>
</menu>

Step 2. Associate XML resource with Xamarin-MaterialSearchBar

searchBar = FindViewById<MaterialSearchBar>(Resource.Id.searchBar);
searchBar.InflateMenu(Resource.Menu.main);

searchBar.PopupMenu.SetOnMenuItemClickListener(new PopupMenuListener());

public class PopupMenuListener : PopupMenu.IOnMenuItemClickListener
{
	public bool OnMenuItemClick(IMenuItem item) {
		switch (item.Id)
		{
			case Resource.Id.action_settings:
				break;
		}
		return false;
	}
}