I'm trying to set up searchView in my activity using Xamarin.Android, and can't seem to bind searchable configuration to my search view (searchInfo in the OnCreateOptionsMenu(IMenu menu) is always null). The searchable configuration is directly copied from example in android doc. I have decompiled the resulting apk, and in android manifest, in the corresponding activity section there was necessary metadata and intent-filter tags. I'm fairly new to the android, any advice is appreciated.
[Activity(Theme = "@style/Theme.AppCompat.NoActionBar")]
[MetaData(name: "android.app.searchable", Resource = "@xml/searchable")]
[IntentFilter(new[] { Intent.ActionSearch })]
public class MainActivity : AppCompatActivity
...
protected override void OnCreate(Bundle savedInstanceState)
{
searchView = new SearchView(this);
...
private SearchView searchView;
public override bool OnCreateOptionsMenu(IMenu menu)
{
var searchManager =
(SearchManager)GetSystemService(Context.SearchService);
var sa = searchManager.SearchablesInGlobalSearch;
var searchInfo = searchManager.GetSearchableInfo(ComponentName);
searchView.SetSearchableInfo(
searchManager.GetSearchableInfo(ComponentName));
var menuItem = menu.Add(0, 2, 0, "search");
menuItem.SetShowAsAction(ShowAsAction.CollapseActionView | ShowAsAction.IfRoom);
var icon = new IconicsDrawable(this, FontAwesome.Icon.FawSearch);
menuItem.SetActionView(searchView);
icon.Color(AppTheme.DarkBlueColor);
icon.SizeDp(20);
menuItem.SetIcon(icon);
return true;
}
Edit: No, that is not a duplicate - my problem was that I didn't read definition of searchable in Android doc: I placed literals instead of resource identifiers as values of these keys:
android:label="@string/search_hint" android:hint="@string/search_hint"
I had something like
android:label="bla" android:hint="bla"
Apparently it this way it cannot be parsed and will always return null (in searchInfo).