Skip to content
Titanium SDK
Version13.2.0

You are reading 13.2.0. See this page in 13.4.1.

Titanium.UI.SearchBar

viewAndroidiPhoneiPadmacOSsince 0.8

Extends Titanium.UI.ViewTitanium.Proxy

A specialized text field for entering search text.

Android iOS
Android iOS

Search bars are most commonly used for filtering the rows in a TableView and ListView. You can add a search bar to a table view via its search property. You can add a search bar to a list view via its searchBar property.

A search bar can also be used on its own.

Use the Titanium.UI.createSearchBar method or Alloy <SearchBar> element to create a search bar.

Android Notes

On Android, the search bar's [x] clear button is used as a cancel button if iconifiedByDefault is set true, causing it to collapse back into an icon. Otherwise, it will only clear the text and you'll receive a change event instead of a cancel event like iOS.

Examples

Simple Search Bar

var search = Titanium.UI.createSearchBar({
  barColor:'#000',
  showCancel:true,
  height:43,
  top:0,
});

Alloy XML Markup

Previous example as an Alloy view.

<Alloy>
    <SearchBar id="search" barColor="#000" showCancel="true" height="43" top="0" />
</Alloy>

Search Bar with TableView

var search = Ti.UI.createSearchBar({
    showCancel: true
});
var tableview = Ti.UI.createTableView({
    search: search
});

Alloy XML Markup

Previous example as an Alloy view.

<Alloy>
    <TableView id="tableview">
        <SearchBar id="search" showCancel="true" />
    </TableView>
</Alloy>

Properties 95

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

autocorrect

Booleansince Android 10.0.0, iPhone 0.8, iPad 0.8, macOS 9.2.0

Determines whether the text in the search bar is autocorrected during typing.

Default: false

Inherited from Titanium.UI.View

A background gradient for the view.

Linear and Radial Gradients

The following code excerpt creates two views, one with a linear gradient and one with a radial gradient.

var win1 = Titanium.UI.createWindow({
    title:'Tab 1',
    backgroundColor:'#fff',
    layout: 'vertical'
});

var radialGradient = Ti.UI.createView({
    top: 10,
    width: 100,
    height: 100,
    backgroundGradient: {
        type: 'radial',
        startPoint: { x: 50, y: 50 },
        endPoint: { x: 50, y: 50 },
        colors: [ 'red', 'blue'],
        startRadius: 50,
        endRadius: 0,
        backfillStart: true
    }
});
var linearGradient = Ti.UI.createView({
    top: 10,
    width: 100,
    height: 100,
    backgroundGradient: {
        type: 'linear',
        startPoint: { x: '0%', y: '50%' },
        endPoint: { x: '100%', y: '50%' },
        colors: [ { color: 'red', offset: 0.0}, { color: 'blue', offset: 0.25 }, { color: 'red', offset: 1.0 } ],
    }
});
win1.add(radialGradient);
win1.add(linearGradient);
win1.open();

Bar color of the search bar view, as a color name or hex triplet.

For information about color values, see the "Colors" section of Titanium.UI.

On iOS and Android, barColor specifies the color of the "frame" around the search text field. On Windows, barColor specifies the color of the whole surrounding area of the search text field.

Default: System default bar color.

borderRadius

Number | String | Array<Number> | Array<String>

Inherited from Titanium.UI.View

Radius for the rounded corners of the view's border.

Default: 0

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

Indicates if the proxy will bubble an event to its parent.

Default: true

cancelButtonTitle

StringiPhoneiPadmacOSsince 5.4.0

The title of the cancel button when the search bar field is focused.

Use this property if you want to display a custom cancel title.

Default: System-localized 'Cancel'

color

String | Titanium.UI.Colorsince 7.1.0

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

For information about color values, see the "Colors" section of Titanium.UI.

elevation

NumberAndroidsince 5.0.0Android 5+

Inherited from Titanium.UI.View

Base elevation of the view relative to its parent in pixels.

fieldBackgroundDisabledImage

StringiPhoneiPadmacOSsince 7.5.0

Background image of the text field in disabled state, specified as a local file path or URL.

If this property is not specified, the default white background is used.

fieldBackgroundImage

StringiPhoneiPadmacOSsince 7.5.0

Background image of the text field, specified as a local file path or URL.

If this property is not specified, the default white background is used.

focusable

BooleanAndroid

Inherited from Titanium.UI.View

Whether view should be focusable while navigating with the trackball.

Default: false

focused

Booleansince 9.1.0read-only

Determines whether this SearchBar has focus.

Default: false

hintText

String

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

Default: On iOS, System-localized 'Search'. On Android and Windows, no hint text.

Key identifying a string from the locale file to use for the hintText property.

Only one of hintText or hinttextid should be specified.

iconColor

String | Titanium.UI.ColorAndroidsince 12.0.0

Color of the search and close icon. Search icon will only work for iconified:false.

layout

String

Inherited from Titanium.UI.View

Specifies how the view positions its children. One of: 'composite', 'vertical', or 'horizontal'.

left

Number | String

Inherited from Titanium.UI.View

View's left position, in platform-specific units.

opacity

Number

Inherited from Titanium.UI.View

Opacity of this view, from 0.0 (transparent) to 1.0 (opaque). Defaults to 1.0 (opaque).

prompt

StringiPhoneiPadmacOS

Single line of text displayed at the top of the search bar.

On Android, this property is no longer supported as of Titanium 10.0.0.

Default: No prompt.

promptid

StringiPhoneiPadmacOS

Key identifying a string from the locale file to use for the prompt property.

On Android, this property is no longer supported as of Titanium 10.0.0.

rect

DimensionWithAbsolutessince 2.0.0read-only

Inherited from Titanium.UI.View

The bounding box of the view relative to its parent, in system units.

rotation

NumberAndroidiPhoneiPadsince Android 5.4.0, iPhone 12.3.0, iPad 12.3.0

Inherited from Titanium.UI.View

Clockwise 2D rotation of the view in degrees.

showBookmark

BooleaniPhoneiPadmacOS

Determines whether the bookmark button is displayed.

Default: false

showCancel

Boolean

Determines whether the cancel button is displayed.

On iOS, you can specify that showing and hiding the cancel button should be animated. The change is not animated by default. To enable animation, call setShowCancel.

Default: false

tokens

Array<String>iPhoneiPadmacOSsince 9.1.0iOS 13.0+

The token of a search text field

Default:

tooltip

Stringsince 12.1.0iOS 15.0+

Inherited from Titanium.UI.View

The default text to display in the control's tooltip.

touchFeedback

BooleanAndroidsince 6.1.0

Inherited from Titanium.UI.View

A material design visual construct that provides an instantaneous visual confirmation of touch point.

Default: false

translationX

NumberAndroidsince 5.0.0

Inherited from Titanium.UI.View

Horizontal location of the view relative to its left position in pixels.

value

String

Value of the search bar.

On Android and before Titanium 10.0.0, the value cannot be set until after the search bar is created.

Methods 18

Inherited from Titanium.Proxy

Adds the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Causes the search bar to lose focus.

convertPointToView

since Android 1.8, iPhone 1.8, iPad 1.8, macOS 9.2.0

Inherited from Titanium.UI.View

Translates a point from this view's coordinate system to another view's coordinate system.

Parameters
ParametersTypeDescription
pointPoint

A point in this view's coordinate system.

If this argument is missing an x or y property, or the properties can not be converted into numbers, an exception will be raised.

destinationViewTitanium.UI.View

View that specifies the destination coordinate system to convert to. If this argument is not a view, an exception will be raised.

Returns Point

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Causes the search bar to gain focus.

getViewById

since 6.1.0

Inherited from Titanium.UI.View

Returns the matching view of a given view ID.

Parameters
ParametersTypeDescription
idString

The ID of the view that should be returned. Use the id property in your views to enable it for indexing in this method.

Inherited from Titanium.UI.View

Hides this view.

Parameters
ParametersTypeDescription
options?AnimatedOptions

Animation options for Android only. Since SDK 5.1.0 and used only on Android 5.0+

Determines whether to enable a circular reveal animation. Note that the default here is equivalent to passing in { animated: false }

insertAt

since 3.3.0

Inherited from Titanium.UI.View

Inserts a view at the specified position in the children array.

Parameters
ParametersTypeDescription
paramsViewPositionOptions

Pass an object that specifies the view to insert and optionally at which position (defaults to end)

2 fields
position? Number

Position in the children array of the view element to replace.

view Titanium.UI.View

View to insert. Required.

insertTokenAtIndex

iPhoneiPadmacOSsince 9.1.0iOS 13.0+

Inserts a new search token at the specified index.

Parameters
ParametersTypeDescription
tokenSearchBarToken

The token to insert

3 fields
identifier String

The identifier of the search bar token.

image? String

The image of the search bar token.

text String

The text of the search bar token (displayed in the search bar).

indexNumber

The index to insert the token at.

Inherited from Titanium.Proxy

Removes the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

removeTokenAtIndex

iPhoneiPadmacOSsince 9.1.0iOS 13.0+

Removes an existing token at the specified index.

Parameters
ParametersTypeDescription
indexNumber

The index to remove the token at.

Shows or hides the cancel button.

Sets the value of the showCancel property.

On iOS, this method can be used to specify animation properties when changing the state of the cancel button.

searchBar.setShowCancel(true, { animated: true });
Parameters
ParametersTypeDescription
showCancelBoolean

New value for showCancel.

options?AnimatedOptions

Dictionary of animation properties. Currently only a single boolean property, animated is supported. Only used on iOS.

Note that the default here is equivalent to passing in { animated: false }

Inherited from Titanium.UI.View

Makes this view visible.

Parameters
ParametersTypeDescription
options?AnimatedOptions

Animation options for Android only. Since SDK 5.1.0 and only used on Android 5.0+

Determines whether to enable a circular reveal animation. Note that the default here is equivalent to passing in { animated: false }

Inherited from Titanium.UI.View

Returns an image of the rendered view, as a Blob.

Parameters
ParametersTypeDescription
callback?Callback<Titanium.Blob>

Function to be invoked upon completion. If non-null, this method will be performed asynchronously. If null, it will be performed immediately.

honorScaleFactor?Boolean

Determines whether the image is scaled based on scale factor of main screen. (iOS only)

When set to true, image is scale factor is honored. When set to false, the image in the blob has the same dimensions for retina and non-retina devices.

Events 22

Fired when the search bar loses focus.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

bookmark

iPhoneiPad

Fired when the bookmark button is pressed.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

Fired when the cancel button is pressed.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

Fired when the value of the search bar changes.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

Inherited from Titanium.UI.View

Fired when the device detects a click against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the click passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a double click against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the double click passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a double tap against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the double tap passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

focus

AndroidiPhoneiPad

Fired when the search bar gains focus.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

keypressed

since Android 3.1.0, iPhone 5.4.0, iPad 5.4.0, macOS 9.2.0

Inherited from Titanium.UI.View

Fired when a hardware key is pressed in the view.

Event properties
Event propertiesTypeDescription
keyCodeNumber

The code for the physical key that was pressed. For more details, see KeyEvent. This API is experimental and subject to change.

Inherited from Titanium.UI.View

Fired when the device detects a long press.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the long press passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

pinch

since 1.8.0

Inherited from Titanium.UI.View

Fired when the device detects a pinch gesture.

Event properties
Event propertiesTypeDescription
scaleNumber

The scale factor relative to the points of the two touches in screen coordinates.

velocityNumber

The velocity of the pinch in scale factor per second.

timeNumber

The event time of the current event being processed.

timeDeltaNumber

The time difference in milliseconds between the previous accepted scaling event and the current scaling event.

currentSpanNumber

The average distance between each of the pointers forming the gesture in progress through the focal point.

currentSpanXNumber

The average X distance between each of the pointers forming the gesture in progress through the focal point.

currentSpanYNumber

The average Y distance between each of the pointers forming the gesture in progress through the focal point.

previousSpanNumber

The previous average distance between each of the pointers forming the gesture in progress through the focal point.

previousSpanXNumber

The previous average X distance between each of the pointers forming the gesture in progress through the focal point.

previousSpanYNumber

The previous average Y distance between each of the pointers forming the gesture in progress through the focal point.

focusXNumber

The X coordinate of the current gesture's focal point.

focusYNumber

The Y coordinate of the current gesture's focal point.

inProgressBoolean

Returns true if a scale gesture is in progress, false otherwise.

Fired when keyboard search button is pressed.

Event properties
Event propertiesTypeDescription
valueString

Value of the search bar.

rotate

since 12.7.0

Inherited from Titanium.UI.View

Fired when the device detects a two finger rotation.

Event properties
Event propertiesTypeDescription
rotateNumber

Rotation in degrees.

Inherited from Titanium.UI.View

Fired when the device detects a single tap against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the single tap passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a swipe gesture against the view.

Event properties
Event propertiesTypeDescription
directionString

Direction of the swipe--either 'left', 'right', 'up', or 'down'.

xNumber

X coordinate of the event's endpoint from the source view's coordinate system.

yNumber

Y coordinate of the event's endpoint from the source view's coordinate system.

obscuredBoolean

Returns true if the swipe passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when a touch event is interrupted by the device.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when a touch event is completed.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Penciland are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired as soon as the device detects movement of a touch.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired as soon as the device detects a touch gesture.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

twofingertap

since 3.0.0

Inherited from Titanium.UI.View

Fired when the device detects a two-finger tap against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the tap passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.