Reputation: 749
Im reading the first part of this tutorial to add a global search on an android app but I don't get this part.
http://developer.android.com/training/search/setup.html
To display the SearchView in the action bar, inflate the XML menu resource (res/menu/options_menu.xml) in the onCreateOptionsMenu() method of your activity:
I't doesn't describe how to "inflate the XML resource" in the tutorial and im not sure where else in the documentation thats at. Does anyone know which file to inject that code into thats below the paragraph above...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
Upvotes: 0
Views: 412
Reputation: 17085
do like this in your activity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return super.onCreateOptionsMenu(menu);
}
and if you need search view in action bar , your menu xml should be something like this
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appname="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search_api_holo_light"
android:title="@string/action_search_title"
appname:showAsAction="collapseActionView|always"
appname:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Upvotes: 1