Search code examples
androidfocussearchview

SearchView queryHint doesn't show when focusing on the view automatically when activity starts


I have an activity that starts with the SearchView focused on it. The thing is, I have a queryHint for the SearchView that does not show when entering the activity, it shows only after typing and deleting something. I need to show this information out from the starts because it is critical that the user is being aware of what written (case sensitivity issues)

here is my SearchView -


<androidx.appcompat.widget.SearchView
        android:id="@+id/activity_search_explore_search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:queryHint="Search - (Case Sensitive)"
        android:layout_marginStart="8dp" />

here the java code that gets it's focus -


mSearchView.setOnFocusChangeListener((view, b) -> mSearchView.setQueryHint("Search - (Case Sensitive)"));
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setFocusable(true);
    mSearchView.requestFocusFromTouch();


Solution

  • add below line in your SearchView.

    app:iconifiedByDefault="false"
    app:queryHint="Search - (Case Sensitive)"