Search code examples
androidsearchview

SearchView show as always


i use widget SearchView

    <SearchView
    android:id="@+id/searchView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@color/white"
    android:inputType="text"
    android:singleLine="true"
    android:layout_alignParentLeft="true"
     />

its work fine , but if search box show up, i always have to click on search icon then. so can anyone help me to make search box show up without click on search icon

search button

search box


Solution

  • Add the attribute

    android:iconifiedByDefault="false"
    

    to the SearchView definition.

    You can add android:windowSoftInputMode="stateHidden" to the activity in the manifest file to prevent the keyboard from displaying; but before you do, think about this: If the user is forced to touch the widget to display the keyboard and enter something, you might as well leave the searchview iconified so that the user can see more of the display underneath.

    If you really want to remove focus, there are a few alternatives, see this post: Stop EditText from gaining focus at Activity startup