# Titanium.UI.Android

The Android-specific UI capabilities. All properties, methods and events in this namespace will only work on Android systems.

# Drawer Layout

The drawer-layout components acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window. It is represented by a centerView and optional leftView and rightView components that can be swiped in and out with additional configuration and transitions. Learn more about drawer-layouts in it's dedicated Titanium.UI.Android.DrawerLayout docs.

Availability
1.0

# Examples

# Android Preferences Example

Create preferences interface for the application.

# app.js

var button = Ti.UI.createButton({
  title:	'Click to Open Preferences'
});
button.addEventListener('click', function() {
  Ti.API.info('Current value for editText: ' + Ti.App.Properties.getString('editText'));
  Ti.UI.Android.openPreferences();
});
currentWindow.add(button);

# platform/android/res/xml/preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="Preferences">
  <PreferenceScreen
      android:title="Misc. Preferences"
      android:summary="Click to see more options">
    <EditTextPreference
      android:title="Edit Text Preference"
      android:summary="You may enter a string"
      android:defaultValue=""
      android:key="editText" />
  </PreferenceScreen>
  <PreferenceCategory android:title="Category One">
    <CheckBoxPreference
      android:title="CheckBox Preference"
      android:defaultValue="false"
      android:summary="You may enter a boolean"
      android:key="checkbox" />
    <RingtonePreference
      android:title="Ringtone Preference"
      android:summary="You may pick a ringtone"
      android:defaultValue=""
      android:key="ringtone" />
  </PreferenceCategory>
  <PreferenceCategory android:title="Category Two">
    <ListPreference
      android:title="List Preference"
      android:summary="You may chose from multiple choices"
      android:key="list"
    android:entries="@array/listNames"
    android:entryValues="@array/listValues"
    />
  </PreferenceCategory>
</PreferenceScreen>

# platform/android/res/values/array/array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string-array name="listNames">
    <item>5 Minutes</item>
    <item>10 Minutes</item>
    <item>15 Minutes</item>
    <item>30 Minutes</item>
    <item>60 Minutes</item>
  </string-array>
  <string-array name="listValues">
    <item>5</item>
    <item>10</item>
    <item>15</item>
    <item>30</item>
    <item>60</item>
  </string-array>
</resources>

# Properties

# apiName READONLY

Availability
3.2.0
apiName :String

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button returns Ti.UI.Button.


# bubbleParent

Availability
3.0.0
bubbleParent :Boolean

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

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true


# lifecycleContainer

Availability
3.6.0

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

# Methods

# addEventListener

Availability
1.0
addEventListener(name, callback) void

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

Parameters

Name Type Description
name String

Name of the event.

callback Callback<Titanium.Event>

Callback function to invoke when the event is fired.

Returns

Type
void

# applyProperties

Availability
3.0.0
applyProperties(props) void

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

Parameters

Name Type Description
props Dictionary

A dictionary of properties to apply.

Returns

Type
void

# createCardView

Availability
5.1.0
createCardView([parameters]) Titanium.UI.Android.CardView

Creates and returns an instance of Titanium.UI.Android.CardView.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.CardView>

Properties to set on a new object, including any defined by Titanium.UI.Android.CardView except those marked not-creation or read-only.

Returns


# createCollapseToolbar

Availability
12.1.0
createCollapseToolbar([parameters]) Titanium.UI.Android.CollapseToolbar

Creates and returns an instance of Titanium.UI.Android.CollapseToolbar.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.CollapseToolbar>

Properties to set on a new object, including any defined by Titanium.UI.Android.CollapseToolbar except those marked not-creation or read-only.

Returns


# createDrawerLayout

Availability
6.2.0
createDrawerLayout([parameters]) Titanium.UI.Android.DrawerLayout

Creates and returns an instance of Titanium.UI.Android.DrawerLayout.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.DrawerLayout>

Properties to set on a new object, including any defined by Titanium.UI.Android.DrawerLayout except those marked not-creation or read-only.

Returns


# createFloatingActionButton

Availability
12.0.0
createFloatingActionButton([parameters]) Titanium.UI.Android.FloatingActionButton

Creates and returns an instance of Titanium.UI.Android.FloatingActionButton.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.FloatingActionButton>

Properties to set on a new object, including any defined by Titanium.UI.Android.FloatingActionButton except those marked not-creation or read-only.

Returns


# createProgressIndicator

Availability
3.0.0
createProgressIndicator([parameters]) Titanium.UI.Android.ProgressIndicator

Creates and returns an instance of Titanium.UI.Android.ProgressIndicator.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.ProgressIndicator>

Properties to set on a new object, including any defined by Titanium.UI.Android.ProgressIndicator except those marked not-creation or read-only.

Returns


# createSearchView

Availability
3.0.2
createSearchView([parameters]) Titanium.UI.Android.SearchView

Creates and returns an instance of Titanium.UI.Android.SearchView.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.SearchView>

Properties to set on a new object, including any defined by Titanium.UI.Android.SearchView except those marked not-creation or read-only.

Returns


# createSnackbar

Availability
11.1.0
createSnackbar([parameters]) Titanium.UI.Android.Snackbar

Creates and returns an instance of Titanium.UI.Android.Snackbar.

Parameters

Name Type Description
parameters Dictionary<Titanium.UI.Android.Snackbar>

Properties to set on a new object, including any defined by Titanium.UI.Android.Snackbar except those marked not-creation or read-only.

Returns


# fireEvent

Availability
1.0
fireEvent(name[, event]) void

Fires a synthesized event to any registered listeners.

Parameters

Name Type Description
name String

Name of the event.

event Dictionary

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

Returns

Type
void

# getColorResource

Availability
9.1.0
getColorResource(resourceIdOrColorName) Titanium.UI.Color

Returns a <Ti.Color> instance for a color defined by the system or user resources (colors.xml)

This method allows converting a known color resource id or short name to an actual color instance.

The resource id values can be accessed via color and <Titanium.App.Android.R.color> properties.

See the official Android Developer documentation for the R.color constants.

Parameters

Name Type Description
resourceIdOrColorName Number | String

integer resource id for a color, or the name of the color defined in the application resources (colors.xml).

Returns


# harmonizedColor

Availability
12.0.0
harmonizedColor(color) String

Creates a harmonizing color

Shifts the hue of the input color towards the hue of colorPrimary and returns a new color as a hex string. Usage: Ti.UI.Android.harmonizedColor("#ff0000");

Parameters

Name Type Description
color String | Titanium.UI.Color

Input Color

Returns

Type
String

# hideSoftKeyboard

Availability
1.0
hideSoftKeyboard() void

Hides the soft keyboard.

Be aware that it is not currently possible in the native Android API to detect that the keyboard is already visible or to globally show the keyboard.

Returns

Type
void

# openPreferences

Availability
1.0
openPreferences() void

Opens an application preferences dialog, using the native Android system settings interface, defined by the platform-specific preferences.xml and array.xml files.

The preferences configuration files must be created in the project folders, platform/android/res/xml/preferences.xml and platform/android/res/values/array/array.xml.

The preferences values can be accessed via Titanium.App.Properties.

See the example for a demonstration, and the official Android Developer documentation for the preferences.xml format.

Returns

Type
void

# removeEventListener

Availability
1.0
removeEventListener(name, callback) void

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

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

Name Type Description
name String

Name of the event.

callback Callback<Titanium.Event>

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

Returns

Type
void

# Constants

# FLAG_LAYOUT_NO_LIMITS

Availability
10.1.0
FLAG_LAYOUT_NO_LIMITS :Number

Flag allowing window to extend into the status bar and navigation bar.

When assigned to windowFlags, this flag will make the window ignore the system's insets such as the top status bar and bottom navigation bar so that they overlap the window. The system may make the status bar and navigation bar completely transparent, but this behavior is not guaranteed to happen.

When using this flag, it's also recommended to set the extendSafeArea property to true.

Warning: Using this flag causes safeAreaPadding to return all zeros. This flag also breaks keyboard adjustPan support.


# FLAG_TRANSLUCENT_NAVIGATION

Availability
7.5.0
FLAG_TRANSLUCENT_NAVIGATION :Number

Window flag which makes the Android system's navigation bar semi-transparent.

When assigned to windowFlags, this flag will make the Android system's bottom navigation bar semi-transparent. This flag will only work if you also set the extendSafeArea property to true.

This flag is only supported by Android 4.4 and newer OS versions. This flag is ignored on older versions. On Android 4.4, navigation bar can only be translucent in portrait mode while newer OS versions support this flag for all orientations.


# FLAG_TRANSLUCENT_STATUS

Availability
7.5.0
FLAG_TRANSLUCENT_STATUS :Number

Window flag which makes the Android system's top status bar semi-transparent.

When assigned to windowFlags, this flag will make the Android system's top status bar semi-transparent. This flag will only work if you also set the extendSafeArea property to true.

This flag is only supported by Android 4.4 and newer OS versions. This flag is ignored on older versions.


# GRAVITY_AXIS_CLIP

Availability
5.4.0
GRAVITY_AXIS_CLIP :Number

Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied.


# GRAVITY_AXIS_PULL_AFTER

Availability
5.4.0
GRAVITY_AXIS_PULL_AFTER :Number

Raw bit controlling how the right/bottom edge is placed.


# GRAVITY_AXIS_PULL_BEFORE

Availability
5.4.0
GRAVITY_AXIS_PULL_BEFORE :Number

Raw bit controlling how the left/top edge is placed.


# GRAVITY_AXIS_SPECIFIED

Availability
5.4.0
GRAVITY_AXIS_SPECIFIED :Number

Raw bit indicating the gravity for an axis has been specified.


# GRAVITY_AXIS_X_SHIFT

Availability
5.4.0
GRAVITY_AXIS_X_SHIFT :Number

Bits defining the horizontal axis.


# GRAVITY_AXIS_Y_SHIFT

Availability
5.4.0
GRAVITY_AXIS_Y_SHIFT :Number

Bits defining the vertical axis.


# GRAVITY_BOTTOM

Availability
5.4.0
GRAVITY_BOTTOM :Number

Push object to the bottom of its container, not changing its size.


# GRAVITY_CENTER

Availability
5.4.0
GRAVITY_CENTER :Number

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.


# GRAVITY_CENTER_HORIZONTAL

Availability
5.4.0
GRAVITY_CENTER_HORIZONTAL :Number

Place object in the horizontal center of its container, not changing its size.


# GRAVITY_CENTER_VERTICAL

Availability
5.4.0
GRAVITY_CENTER_VERTICAL :Number

Place object in the vertical center of its container, not changing its size.


# GRAVITY_CLIP_HORIZONTAL

Availability
5.4.0
GRAVITY_CLIP_HORIZONTAL :Number

Flag to clip the edges of the object to its container along the horizontal axis.


# GRAVITY_CLIP_VERTICAL

Availability
5.4.0
GRAVITY_CLIP_VERTICAL :Number

Flag to clip the edges of the object to its container along the vertical axis.


# GRAVITY_DISPLAY_CLIP_HORIZONTAL

Availability
5.4.0
GRAVITY_DISPLAY_CLIP_HORIZONTAL :Number

Special constant to enable clipping to an overall display along the horizontal dimension.


# GRAVITY_DISPLAY_CLIP_VERTICAL

Availability
5.4.0
GRAVITY_DISPLAY_CLIP_VERTICAL :Number

Special constant to enable clipping to an overall display along the vertical dimension.


# GRAVITY_END

Availability
5.4.0
GRAVITY_END :Number

Push object to x-axis position at the end of its container, not changing its size.


# GRAVITY_FILL

Availability
5.4.0
GRAVITY_FILL :Number

Grow the horizontal and vertical size of the object if needed so it completely fills its container.


# GRAVITY_FILL_HORIZONTAL

Availability
5.4.0
GRAVITY_FILL_HORIZONTAL :Number

Grow the horizontal size of the object if needed so it completely fills its container.


# GRAVITY_FILL_VERTICAL

Availability
5.4.0
GRAVITY_FILL_VERTICAL :Number

Grow the vertical size of the object if needed so it completely fills its container.


# GRAVITY_HORIZONTAL_GRAVITY_MASK

Availability
5.4.0
GRAVITY_HORIZONTAL_GRAVITY_MASK :Number

Binary mask to get the absolute horizontal gravity of a gravity.


# GRAVITY_LEFT

Availability
5.4.0
GRAVITY_LEFT :Number

Push object to the left of its container, not changing its size.


# GRAVITY_NO_GRAVITY

Availability
5.4.0
GRAVITY_NO_GRAVITY :Number

Constant indicating that no gravity has been set


# GRAVITY_RELATIVE_HORIZONTAL_GRAVITY_MASK

Availability
5.4.0
GRAVITY_RELATIVE_HORIZONTAL_GRAVITY_MASK :Number

Binary mask for the horizontal gravity and script specific direction bit.


# GRAVITY_RELATIVE_LAYOUT_DIRECTION

Availability
5.4.0
GRAVITY_RELATIVE_LAYOUT_DIRECTION :Number

Raw bit controlling whether the layout direction is relative or not (GRAVITY_START/GRAVITY_END instead of absolute GRAVITY_LEFT/GRAVITY_RIGHT).


# GRAVITY_RIGHT

Availability
5.4.0
GRAVITY_RIGHT :Number

Push object to the right of its container, not changing its size.


# GRAVITY_START

Availability
5.4.0
GRAVITY_START :Number

Push object to x-axis position at the start of its container, not changing its size.


# GRAVITY_TOP

Availability
5.4.0
GRAVITY_TOP :Number

Push object to the top of its container, not changing its size.


# GRAVITY_VERTICAL_GRAVITY_MASK

Availability
5.4.0
GRAVITY_VERTICAL_GRAVITY_MASK :Number

Binary mask to get the vertical gravity of a gravity.


# OVER_SCROLL_ALWAYS

Availability
3.1.0
OVER_SCROLL_ALWAYS :Number

Always allow a user to over-scroll this view, provided it is a view that can scroll.

Use this with the following properties - overScrollMode, overScrollMode, overScrollMode and overScrollMode.

Only applicable when API_LEVEL is 9 or above.


# OVER_SCROLL_IF_CONTENT_SCROLLS

Availability
3.1.0
OVER_SCROLL_IF_CONTENT_SCROLLS :Number

Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.

Use this with the following properties - overScrollMode, overScrollMode, overScrollMode and overScrollMode.

Only applicable when API_LEVEL is 9 or above.


# OVER_SCROLL_NEVER

Availability
3.1.0
OVER_SCROLL_NEVER :Number

Never allow a user to over-scroll this view.

Use this with the following properties - overScrollMode, overScrollMode, overScrollMode and overScrollMode.

Only applicable when API_LEVEL is 9 or above.


# PIXEL_FORMAT_A_8

Availability
1.8.0
PIXEL_FORMAT_A_8 :Number

Android A_8 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_L_8

Availability
1.8.0
PIXEL_FORMAT_L_8 :Number

Android L_8 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_LA_88

Availability
1.8.0
PIXEL_FORMAT_LA_88 :Number

Android LA_88 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_OPAQUE

Availability
1.8.0
PIXEL_FORMAT_OPAQUE :Number

Android OPAQUE pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGB_332

Availability
1.8.0
PIXEL_FORMAT_RGB_332 :Number

Android RGB_332 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGB_565

Availability
1.8.0
PIXEL_FORMAT_RGB_565 :Number

Android RGB_565 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGB_888

Availability
1.8.0
PIXEL_FORMAT_RGB_888 :Number

Android RGB_888 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGBA_4444

Availability
1.8.0
PIXEL_FORMAT_RGBA_4444 :Number

Android RGBA_4444 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGBA_5551

Availability
1.8.0
PIXEL_FORMAT_RGBA_5551 :Number

Android RGBA_5551 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGBA_8888

Availability
1.8.0
PIXEL_FORMAT_RGBA_8888 :Number

Android RGBA_8888 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_RGBX_8888

Availability
1.8.0
PIXEL_FORMAT_RGBX_8888 :Number

Android RGBX_8888 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_TRANSLUCENT

Availability
1.8.0
PIXEL_FORMAT_TRANSLUCENT :Number

Android TRANSLUCENT pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_TRANSPARENT

Availability
1.8.0
PIXEL_FORMAT_TRANSPARENT :Number

Android A_8 pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PIXEL_FORMAT_UNKNOWN

Availability
1.8.0
PIXEL_FORMAT_UNKNOWN :Number

Android UNKNOWN pixel format for Titanium.UI.Window. Selecting the correct pixel format can improve image clarity and performance.

See the Android Developer website for official documentation about the PixelFormat constants.


# PROGRESS_INDICATOR_DETERMINANT

Availability
3.0.0
PROGRESS_INDICATOR_DETERMINANT :Number

Used with the type property to indicate an ongoing activity of determinate length.


# PROGRESS_INDICATOR_DIALOG

Availability
3.0.0
PROGRESS_INDICATOR_DIALOG :Number

Display Titanium.UI.Android.ProgressIndicator as a modal dialog. (default)

Used with the location property.


# PROGRESS_INDICATOR_INDETERMINANT

Availability
3.0.0
PROGRESS_INDICATOR_INDETERMINANT :Number

Used with the type property to indicate an ongoing activity of indeterminate length. (default)


# PROGRESS_INDICATOR_STATUS_BAR

Availability
3.0.0
PROGRESS_INDICATOR_STATUS_BAR :Number

Display Titanium.UI.Android.ProgressIndicator as a horizontal progress bar in the title of the window.

Used with the location property.


# SCROLL_FLAG_ENTER_ALWAYS

Availability
12.1.0
SCROLL_FLAG_ENTER_ALWAYS :Number

When entering (scrolling on screen) the view will scroll on any downwards scroll event, regardless of whether the scrolling view is also scrolling. This is commonly referred to as the 'quick return' pattern.


# SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED

Availability
12.1.0
SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED :Number

An additional flag for 'enterAlways' which modifies the returning view to only initially scroll back to it's collapsed height. Once the scrolling view has reached the end of it's scroll range, the remainder of this view will be scrolled into view. The collapsed height is defined by the view's minimum height.


# SCROLL_FLAG_EXIT_UNTIL_COLLAPSED

Availability
12.1.0
SCROLL_FLAG_EXIT_UNTIL_COLLAPSED :Number

When exiting (scrolling off screen) the view will be scrolled until it is 'collapsed'. The collapsed height is defined by the view's minimum height.


# SCROLL_FLAG_NO_SCROLL

Availability
12.1.0
SCROLL_FLAG_NO_SCROLL :Number

Disable scrolling on the view. This flag should not be combined with any of the other scroll flags.


# SCROLL_FLAG_SCROLL

Availability
12.1.0
SCROLL_FLAG_SCROLL :Number

The view will be scroll in direct relation to scroll events. This flag needs to be set for any of the other flags to take effect. If any sibling views before this one do not have this flag, then this value has no effect.


# SCROLL_FLAG_SNAP

Availability
12.1.0
SCROLL_FLAG_SNAP :Number

Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to its closest edge. For example, if the view only has its bottom 25% displayed, it will be scrolled off screen completely. Conversely, if its bottom 75% is visible then it will be scrolled fully into view.


# SCROLL_FLAG_SNAP_MARGINS

Availability
12.1.0
SCROLL_FLAG_SNAP_MARGINS :Number

An additional flag to be used with 'snap'. If set, the view will be snapped to its top and bottom margins, as opposed to the edges of the view itself.