Skip to content
Titanium SDK
Version12.6.2

You are reading 12.6.2. See this page in 13.4.1.

Titanium.UI.Android

moduleAndroidsince 1.0

Extends Titanium.ModuleTitanium.Proxy

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.

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 103

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.

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

FLAG_LAYOUT_NO_LIMITS

Numbersince 10.1.0read-only

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

When assigned to Window.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 Window.extendSafeArea property to true.

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

FLAG_TRANSLUCENT_NAVIGATION

Numbersince 7.5.0read-only

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

When assigned to Titanium.UI.Window.windowFlags, this flag will make the Android system's bottom navigation bar semi-transparent. This flag will only work if you also set the Window.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

Numbersince 7.5.0read-only

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

When assigned to Titanium.UI.Window.windowFlags, this flag will make the Android system's top status bar semi-transparent. This flag will only work if you also set the Titanium.UI.Window.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

Numbersince 5.4.0read-only

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

GRAVITY_AXIS_SPECIFIED

Numbersince 5.4.0read-only

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

GRAVITY_BOTTOM

Numbersince 5.4.0read-only

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

GRAVITY_CENTER

Numbersince 5.4.0read-only

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

GRAVITY_CENTER_HORIZONTAL

Numbersince 5.4.0read-only

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

GRAVITY_CENTER_VERTICAL

Numbersince 5.4.0read-only

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

GRAVITY_CLIP_HORIZONTAL

Numbersince 5.4.0read-only

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

GRAVITY_CLIP_VERTICAL

Numbersince 5.4.0read-only

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

GRAVITY_END

Numbersince 5.4.0read-only

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

GRAVITY_FILL

Numbersince 5.4.0read-only

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

GRAVITY_FILL_HORIZONTAL

Numbersince 5.4.0read-only

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

GRAVITY_FILL_VERTICAL

Numbersince 5.4.0read-only

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

GRAVITY_LEFT

Numbersince 5.4.0read-only

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

GRAVITY_NO_GRAVITY

Numbersince 5.4.0read-only

Constant indicating that no gravity has been set

GRAVITY_RELATIVE_LAYOUT_DIRECTION

Numbersince 5.4.0read-only

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

GRAVITY_RIGHT

Numbersince 5.4.0read-only

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

GRAVITY_START

Numbersince 5.4.0read-only

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

GRAVITY_TOP

Numbersince 5.4.0read-only

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

PIXEL_FORMAT_A_8

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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

Numbersince 1.8.0read-only

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.

SCROLL_FLAG_ENTER_ALWAYS

Numbersince 12.1.0read-only

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

Numbersince 12.1.0read-only

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

Numbersince 12.1.0read-only

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

Numbersince 12.1.0read-only

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

SCROLL_FLAG_SCROLL

Numbersince 12.1.0read-only

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

Numbersince 12.1.0read-only

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

Numbersince 12.1.0read-only

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.

Use the system-default behavior to determine how the soft input area (ie software keyboard) is accomodated by the current heavyweight window when it receives focus (default.)

Depends on the AndroidManifest.xml setting if defined or system-default otherwise to determine how to accomodate the soft keyboard when visible.

Used with the Titanium.UI.Window.windowSoftInputMode property.

One of the group of soft input adjustment constants, SOFT_INPUT_ADJUST_UNSPECIFIED, SOFT_INPUT_ADJUST_RESIZE, and SOFT_INPUT_ADJUST_PAN.

Always hide the soft input area (ie software keyboard) when the current heavyweight window receives focus.

Note that the unresolved bug #7115 on the Official Android Project website affects this functionality.

Used with the Titanium.UI.Window.windowSoftInputMode property.

One of the group of soft input visibility constants, SOFT_INPUT_STATE_ALWAYS_HIDDEN, SOFT_INPUT_STATE_ALWAYS_VISIBLE, SOFT_INPUT_STATE_HIDDEN, SOFT_INPUT_STATE_UNSPECIFIED, and SOFT_INPUT_STATE_VISIBLE.

Attempt to hide the soft keyboard when a view receives focus. Note: system can override request.

Attempt to show the soft keyboard when a view receives focus. Note: system can override request.

TAB_MODE_FIXED

Numbersince 12.2.0

Set the TabGroup tab mode to fixed (default).

TABS_STYLE_BOTTOM_NAVIGATION

Numbersince 8.0.0read-only

TabGroup style taking advantage of a bottom navigation controller for switching between tabs.

TABS_STYLE_DEFAULT

Numbersince 8.0.0read-only

The default TabGroup style that places the Tabs bellow the ActionBar and above the Window content.

TRANSITION_CHANGE_BOUNDS

Numbersince 5.2.0read-only

Captures layout bounds of target views before and after the scene change and animates those changes during the transition.

Use this only for shared element transition. Refers to ChangeBounds transition.

TRANSITION_CHANGE_CLIP_BOUNDS

Numbersince 5.2.0read-only

Captures the clip bounds before and after the scene change and animates those changes during the transition.

Use this only for shared element transition. Refers to ChangeClipBounds transition.

TRANSITION_CHANGE_TRANSFORM

Numbersince 5.2.0read-only

Captures scale and rotation for Views before and after the scene change and animates those changes during the transition.

Use this only for shared element transition. Refers to ChangeTransform transition.

TRANSITION_EXPLODE

Numbersince 5.2.0read-only

Moves views in or out from the edges of the scene.

Use this only for activity transition. Refers to Explode transition.

TRANSITION_FADE_IN

Numbersince 5.2.0read-only

Fades in the views.

Use this only for activity transition. Refers to Fade transition.

TRANSITION_FADE_OUT

Numbersince 5.2.0read-only

Fades out the views.

Use this only for activity transition. Refers to Fade transition.

TRANSITION_NONE

Numbersince 5.2.0read-only

Resets transition to platform default.

Can be used with activity and shared element transtion.

TRANSITION_SLIDE_LEFT

Numbersince 5.2.0read-only

Moves views to left.

Use this only for activity transition. Refers to Slide transition.

TRANSITION_SLIDE_RIGHT

Numbersince 5.2.0read-only

Moves views to right.

Use this only for activity transition. Refers to Slide transition.

TRANSITION_SLIDE_TOP

Numbersince 5.2.0read-only

Moves views to top.

Use this only for activity transition. Refers to Slide transition.

WEBVIEW_LOAD_CACHE_ELSE_NETWORK

Numbersince 3.2.0read-only

Use with WebView.cacheMode to override how the cache is used in a web view.

Use cached resources when they're available, even when they're expired. Otherwise load resources via network.

WEBVIEW_PLUGINS_OFF

Numberread-only

Use with WebView.pluginState to disable plugins in a web view.

Content that requires a plugin, is not loaded, and any alternative content is displayed instead.

WEBVIEW_PLUGINS_ON

Numberread-only

Use with WebView.pluginState to enable plugins in a web view.

Content that requires a plugin,, is always loaded, whether or not a plugin is available for the content.

Display a placeholder and only load plugins when user selects it.

Content that requires a plugin, is replaced by a placeholder. When the user clicks on the placeholder, the plugin is loaded and the content is displayed.

Use with WebView.pluginState to load plugins on demand.

Methods 16

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.

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.

getColorResource

since 9.1.0

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 Titanium.Android.R.color and <Titanium.App.Android.R.color> properties.

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

Parameters
ParametersTypeDescription
resourceIdOrColorNameNumber | String

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

harmonizedColor

since 12.0.0

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
ParametersTypeDescription
colorString | Titanium.UI.Color

Input Color

Returns String

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.

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.

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.