Android - Search View: tooltip visible

Is there a way that the search hint is always visible? I want, even if the search is not selected, the user can see what his goal is.

    <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 by default it activates the search.

thanks

+4
source share
2 answers

Here is my solution. This is a bit of a workaround, but still 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 displayed, and when (and only when) the first activity is launched, the SearchView focus is automatically cleared, hiding the keyboard. The keyboard will be displayed with manual or manual orientation of the SearchView.

+4
source

searchView.setQueryHint( " " )? .

+3

Source: https://habr.com/ru/post/1612304/


All Articles