Last active
October 7, 2015 10:18
-
-
Save taig/3149956 to your computer and use it in GitHub Desktop.
Add SearchWidget to Android ActionBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity extends android.app.Activity | |
{ | |
@Override | |
public boolean onCreateOptionsMenu( Menu menu ) | |
{ | |
getMenuInflater().inflate( R.menu.main, menu ); | |
// Add SearchWidget. | |
SearchManager searchManager = (SearchManager) getSystemService( Context.SEARCH_SERVICE ); | |
SearchView searchView = (SearchView) menu.findItem( R.id.options_menu_main_search ).getActionView(); | |
searchView.setSearchableInfo( searchManager.getSearchableInfo( getComponentName() ) ); | |
return super.onCreateOptionsMenu( menu ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | |
<application> | |
<meta-data | |
android:name="android.app.default_searchable" | |
android:value=".app.Search" /> | |
<activity android:name=".activities.Search" > | |
<intent-filter> | |
<action android:name="android.intent.action.SEARCH" /> | |
</intent-filter> | |
<meta-data | |
android:name="android.app.searchable" | |
android:resource="@xml/searchable" /> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Search extends Activity | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<searchable xmlns:android="http://schemas.android.com/apk/res/android" | |
android:hint="@string/search_hint" | |
android:includeInGlobalSearch="false" | |
android:label="@string/search_label" | |
android:searchSettingsDescription="@string/search_global_description" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment