Search code examples
androidandroid-layoutandroid-widgetsearchview

How to add label in a SearchView outside of action bar?


Screenshot

How do I add a label in a SearchView? At first I used an ImageButton and Text combination to achieve the display that I wanted. (See screenshot, 2nd row) I switched to a SearchView and I'm wondering how can I modify how it looks so it's the same as ImageButton/Text combination?


Solution

  • Add a hint to the search view. See this documentation.

    Create a Searchable Configuration

    A searchable configuration defines how the SearchView behaves and is defined in a res/xml/searchable.xml file. At a minimum, a searchable configuration must contain an android:label attribute that has the same value as the android:label attribute of the or element in your Android manifest. However, we also recommend adding an android:hint attribute to give the user an idea of what to enter into the search box:

    <?xml version="1.0" encoding="utf-8"?>
    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
            android:label="@string/app_name"
            android:hint="@string/search_hint" />