API Reference / Android Widgets / searchBox
Apr. 24, 2019
Widget signature
<com.algolia.instantsearch.ui.views.SearchBox
  android:id="@+id/searchBox"

  <!-- Optional parameters -->
  algolia:autofocus="boolean"
  algolia:submitButtonEnabled="boolean"
  algolia:variant="string"
/>

About this widget

The SearchBox widget is used to let the user perform a text-based query.

This usually is the main entry point to start the search in an InstantSearch context. It is usually placed at the top of a search experience, so that the user can start searching right away.

Examples

1
2
3
4
5
6
7
8
<com.algolia.instantsearch.ui.views.SearchBox
  android:id="@+id/searchBox"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:iconifiedByDefault="false"
  android:queryHint="Search"
  algolia:autofocus="false"
  algolia:submitButtonEnabled="false" />

Parameters

autofocus
type: boolean
default: false

Whether the widget should request the user’s focus when displayed.

1
algolia:autofocus="true"
submitButtonEnabled
type: boolean
default: false

Whether the widget should display a submit button. This button is hidden by default: as every keystroke updates the results, it is usually misleading to display a submit button.

1
algolia:submitButtonEnabled="true"
variant
type: string

An identifier for the widget group this widget is part of. If specified, this widget is only linked to other widgets that have the same variant. See Multi-Index Searches.

1
algolia:variant="actors"

Progress indicator

A useful pattern to improve your user’s experience consists of displaying a progress indicator when there are ongoing requests that are still waiting to complete.

By default, InstantSearch displays an indeterminate ProgressBar in your SearchView as long as some requests are still incomplete. This loader uses animations when the target device is recent enough (>= API 14), or after a small delay to avoid blinking. You can change this delay by calling InstantSearch#enableProgressBar(int) with a delay in milliseconds, or disable this progress indicator altogether with InstantSearch#disableProgressBar().

Alternatively, you can implement your own progress logic by using a SearchProgressController. Once instantiated, a SearchProgressController informs its ProgressListener when some requests are sent with onStart(), and calls onStop() when all current requests have returned.

Did you find this page helpful?