SearchView hint not showing

I am trying to display hint text in a search box in my main activity. OnqueryTextSubmit launches another action called SearchResultsActivity, which displays the query results. My problem is that I cannot display the help text. My code is searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="@string/search_hint" android:label="@string/app_name" /> 

and manifest code

 <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.SEARCH"/> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <meta-data android:name="android.app.default_searchable1" android:value=".SearchResultsActivity" android:resource="@xml/searchable"/> </activity> <activity android:name=".SearchResultsActivity"> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"> </meta-data> </activity> </application> </manifest> 

and complete my onQueryTextSubmit code

 @Override public boolean onQueryTextSubmit(String query) { Anniversaries tempResults; tempResults = mainAnniversariesManager.searchManager.searchAnniversaries(query); if (tempResults.entries.size() == 0) { snackbar = Snackbar.make(findViewById(R.id.coordinator), getString(R.string.no_results_found) + query, Snackbar.LENGTH_INDEFINITE); snackbar.show(); return true; } else { snackbar = null; if (!searchView.isIconified()) { searchView.setIconified(true); } menuItem.collapseActionView(); Intent intent=new Intent(getApplicationContext(),SearchResultsActivity.class); Bundle args=new Bundle(); args.putSerializable("serialized_Anniversaries",tempResults); intent.putExtra("args",args); startActivity(intent); return false; } } 

Thank you in advance

+5
source share
4 answers

To add SearchView tooltip text, use the following code:

 search.setQueryHint("Custom Search Hint"); 
+11
source

try using app:queryHint="@string/search" app:defaultQueryHint="@string/search"

+4
source

According to Create configuration for search

If you use SearchView as an action type in the application bar, you need to map the configuration to searchability using SearchView by calling setSearchableInfo(SearchableInfo) .

 SearchManager sm = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(sm.getSearchableInfo(getComponentName())); 
0
source

for me no solutions didn’t work.

I get an instance of edittext searchview, and then, I set a hint for this.

 EditText et= (EditText) mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); et.setHint(context.getString(R.string.search)); 
0
source

All Articles