Is there a way to have the query hint of a Search view always visible? What I want is even if the search view is not selected, the user can see what is it purpose.
<SearchView
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:queryHint="@string/searchHint" />
I tried searchView.setIconifiedByDefault(false);
but it activate the search view by default.
Thanks
Here is my solution. It's a bit of a workaround, but so far works for me.
// Boolean to determine if the activity has just been launched
private boolean activityStartup = true;
// Inside onCreate
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (activityStartup) {
searchView.clearFocus();
activityStartup = false;
}
}
}
});
Thus the query hint is always show, and when (and only when) the activity first launches, the SearchView focus is automatically cleared, hiding the keyboard. The keyboard will be shown when the SearchView is tapped/focused manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With