SearchView hint not showing

try to use app:queryHint="@string/search" app:defaultQueryHint="@string/search"


To add SearchView hint text use the following code :

search.setQueryHint("Custom Search Hint");

for me non of the solutions did not work.

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

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

Using the XML configuration.

This worked for me :

<SearchView
            .
            .
            .
            android:queryHint="@string/search_hint"
            android:iconifiedByDefault="false"    />  

If the hint's desired to be visible in the Non-Active State of SearchView set android:iconifiedByDefault to "false".

If it's undesired set android:iconifiedByDefault to "true".