# Titanium.UI.Android.SearchView

> A specialized text field for entering search text.

- Source: https://titaniumsdk.com/docs/sdk/13.1.0/Titanium.UI.Android.SearchView
- Titanium SDK version: 13.1.0
- Kind: view
- Platforms: Android
- Since: Titanium SDK 3.0.2
- Extends: Titanium.UI.View
- Inheritance: Titanium.UI.View > Titanium.Proxy

| Android |
| ------- |
| ![Android](./searchview_android.png) |

`SearchView` provides a user interface to enter a search query and submit a request to a search provider.

Search views are most commonly used for filtering the rows in a [TableView](https://titaniumsdk.com/docs/sdk/Titanium.UI.TableView.md).
Similar to [SearchBar](https://titaniumsdk.com/docs/sdk/Titanium.UI.SearchBar.md), you can add a search view to a table view by setting the table view's
[search](https://titaniumsdk.com/docs/sdk/Titanium.UI.TableView.md#search) property. A search view can be used without a `TableView`.

You can also use a `SearchView` object as the [Titanium.UI.ListView.searchView](https://titaniumsdk.com/docs/sdk/Titanium.UI.ListView.md#searchView)
property of a [ListView](https://titaniumsdk.com/docs/sdk/Titanium.UI.ListView.md) object.

You can also add `SearchView` to an `ActionBar` as a view (see example below).

Use the [Titanium.UI.Android.createSearchView](https://titaniumsdk.com/docs/sdk/Titanium.UI.Android.md#createSearchView) method or **`<SearchView>`** Alloy element to create
a search view. You must set the Alloy element's `ns` attribute to **Ti.UI.Android**:

``` xml
<SearchView ns="Ti.UI.Android" platform="android"/>
```

## Example: Search View for Table in Action Bar

The following example creates a SearchView widget for a TableView
and displays it as an Action Bar item if the Google API level is 11 or later.
If not, it defaults to use the search bar.

``` js
var win = Ti.UI.createWindow({
    fullscreen: false
});

// Use action bar search view
var search = Ti.UI.Android.createSearchView({
    hintText: "Table Search"
});

win.activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;
    var menuItem = menu.add({
        title: 'Table Search',
        actionView : search,
        icon: (Ti.Android.R.drawable.ic_menu_search ? Ti.Android.R.drawable.ic_menu_search : "my_search.png"),
        showAsAction: Ti.Android.SHOW_AS_ACTION_IF_ROOM | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
    });
};

var data = [];
data.push(Ti.UI.createTableViewRow({title:'Apple'}));
data.push(Ti.UI.createTableViewRow({title:'Banana'}));
data.push(Ti.UI.createTableViewRow({title:'Orange'}));
data.push(Ti.UI.createTableViewRow({title:'Raspberry'}));

var tableview = Titanium.UI.createTableView({
    data: data,
    search: search,
    searchAsChild: false
});

win.add(tableview);
win.open();
```

## Example: Alloy XML Markup

Previous example as an Alloy project.

index.xml:
``` xml
<Alloy>
    <Window id="win" backgroundColor="blue" fullscreen="false" layout="vertical">
        <TableView id="tableview" top="10" searchAsChild="false">
            <TableViewRow title="Apple" />
            <TableViewRow title="Banana" />
            <TableViewRow title="Orange" />
            <TableViewRow title="Raspberry" />
        </TableView>
    </Window>
</Alloy>
```

index.js:
``` js
// use action bar search view
var search = Alloy.createController("searchview").getView();
$.tableview.search = search;
$.win.addEventListener("open", function() {
    $.win.activity.onCreateOptionsMenu = function(e) {
        e.menu.add({
            title: "Table Search",
            icon: (Ti.Android.R.drawable.ic_menu_search ? Ti.Android.R.drawable.ic_menu_search : "my_search.png"),
            actionView: search,
            showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
        });
    }
    $.win.activity.invalidateOptionsMenu();
});

$.win.open();
```

searchview.xml:
``` xml
<Alloy>
    <SearchView id="searchView" ns="Ti.UI.Android" platform="android" hintText="Table Search" />
</Alloy>
```

## Properties

### color

- Type: String
- Platforms: Android

Color of the text in this SearchView, as a color name or hex triplet.

For information about color values, see the "Colors" section of [Titanium.UI](https://titaniumsdk.com/docs/sdk/Titanium.UI.md).

### hintText

- Type: String
- Platforms: Android
- Default: `no hint text`

Text to show when the search view field is not focused.

### hintTextColor

- Type: String
- Platforms: Android
- Since: Titanium SDK 7.1.0
- Default: `Default Android theme's hint text color.`

Color of hint text that displays when field is empty.

Color of hint text that displays when field is empty.

### iconified

- Type: Boolean
- Platforms: Android
- Default: `undefined`

Iconifies or expands the search view

see [Android Documentation](https://developer.android.com/reference/android/widget/SearchView.html#setIconified(boolean)) for more details.

### iconifiedByDefault

- Type: Boolean
- Platforms: Android
- Default: `true`

Sets the default or resting state of the search view

see [Android Documentation](https://developer.android.com/reference/android/widget/SearchView.html#setIconifiedByDefault(boolean)) for more details.

### submitEnabled

- Type: Boolean
- Platforms: Android
- Default: `undefined`

Whether to display the submit button when necessary or never display.

### value

- Type: String
- Platforms: Android

Value of the search view.

This value cannot be set until after the search view is created.

## Methods

### blur

- Platforms: Android

Causes the search view to lose focus.

### focus

- Platforms: Android

Causes the search view to gain focus.

## Events

### blur

- Platforms: Android

Fired when the search view loses focus.

### cancel

- Platforms: Android

Fired when the cancel button is pressed.

Due to the current [Android Issue](http://code.google.com/p/android/issues/detail?id=25758), this event does not work
with Android 4.0+. Alternatively, when using SearchView in the action bar, you can listen for the [MenuItem.collapse](https://titaniumsdk.com/docs/sdk/Titanium.Android.MenuItem.md#collapse) event.

### change

- Platforms: Android

Fired when the value of the search view changes.

### focus

- Platforms: Android

Fired when the search view gains focus.

### submit

- Platforms: Android

If the search query is not empty, fired when the search button is clicked on soft keyboard

## Inherited members

91 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/13.1.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`
- [Titanium.UI.View](https://titaniumsdk.com/docs/sdk/13.1.0/Titanium.UI.View.md): `accessibilityDisableLongPress`, `accessibilityHidden`, `accessibilityHint`, `accessibilityLabel`, `accessibilityValue`, `anchorPoint`, `animate`, `backgroundColor`, `backgroundDisabledColor`, `backgroundDisabledImage`, `backgroundFocusedColor`, `backgroundFocusedImage`, `backgroundGradient`, `backgroundImage`, `backgroundRepeat`, `backgroundSelectedColor`, `backgroundSelectedImage`, `borderColor`, `borderRadius`, `borderWidth`, `bottom`, `center`, `children`, `click`, `convertPointToView`, `dblclick`, `doubletap`, `elevation`, `filterTouchesWhenObscured`, `focusable`, `getViewById`, `height`, `hiddenBehavior`, `hide`, `horizontalWrap`, `id`, `insertAt`, `keepScreenOn`, `keypressed`, `layout`, `left`, `longclick`, `longpress`, `opacity`, `overrideCurrentAnimation`, `pinch`, `postlayout`, `rect`, `remove`, `removeAllChildren`, `replaceAt`, `right`, `rotate`, `rotation`, `rotationX`, `rotationY`, `scaleX`, `scaleY`, `show`, `singletap`, `size`, `softKeyboardOnFocus`, `stopAnimation`, `swipe`, `toImage`, `tooltip`, `top`, `touchEnabled`, `touchFeedback`, `touchFeedbackColor`, `touchcancel`, `touchend`, `touchmove`, `touchstart`, `transform`, `transitionName`, `translationX`, `translationY`, `translationZ`, `twofingertap`, `viewShadowColor`, `visible`, `width`, `zIndex`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

