I want to create a hint for the user in my Search-view, however the hint isn't visible until the user presses the magnifying glass icon. Is the there a way to show the hint even if the user didn't click anything just like with Edit-text? Moreover I want the borders of the search view to be visible and not just the icon, is there a way to achieve it? Thanks in advance.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header_image_id"
android:orientation="vertical"
android:layoutDirection="rtl">
<TextView
android:id="@+id/text_view_id"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAlignment="center"
android:text="Enter your search request here?"/>
<SearchView
android:id="@+id/search_view_id"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:queryHint="This is a hint" />
</LinearLayout>
Using the XML configuration. 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" . This is the answer without creating a function or code in the Activity. Just add this in the layout.
SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
Search View widget is used to provide a search interface to user so that the user can enter his search query and submit a request to search provider and get a list of query suggestions or results. It consist of Relative Layout with ListView in it from which data is to be search.
We have attribute for that setIconifiedByDefault (boolean iconified)
Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.
The default value is true. https://developer.android.com/reference/android/widget/SearchView.html#setIconifiedByDefault(boolean)
What you need to do:
<SearchView
android:id="@+id/search_view_id"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:queryHint="This is a hint"
android:iconifiedByDefault="false"/>
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