Does anybody knows how to set android search dialog hint dynamically? T have try to do something like:
There is a much simpler answer than any of the above. It loads the default searchable.xml for your activity, and then uses java reflection to update the private mHintId field inside the SearchableInfo instance:
@Override
public void onPrepareOptionsMenu(Menu menu) {
SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
SearchableInfo si = searchManager.getSearchableInfo( getActivity().getComponentName() );
try {
Field mHintId = si.getClass().getDeclaredField("mHintId");
mHintId.setAccessible(true);
mHintId.setInt(si, R.string.your_custom_hint);
} catch (Exception e) {
}
MenuItem mi = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView)mi.getActionView();
searchView.setSearchableInfo( si );
}