Search code examples
androidsearchview

Searchbox with hint and search icon on left


I want to to create a searchview which should have a search icon and hint (as in EditText) . The default searchview in android has only the search icon . It does not have hint like edittext.

I am able to add hint to searchview but it is only visible after clicking on the search icon on the search-view . I am using the following code to add hint to the search-view .

String locationSearchViewSetQueryHint = "<font color = #ffffff>Location</font>" 
     locationSearchView.setQueryHint(Html.fromHtml(locationSearchViewSetQueryHint))

How can I show the hint with search icon?


Solution

  • Use this

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
               android:padding="5dp"
        android:background="@drawable/edit_text_bg"
        android:gravity="left"
        android:hint="Search"
        android:drawableStart="@drawable/search_icon">