# Titanium.UI.Android.DrawerLayout
A panel that displays the app's main navigation options on the left edge of the screen.
# Overview
DrawerLayout 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.
As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content.
For design guidelines, see Google Design Guidelines: DrawerLayout (opens new window)
# Examples
# Simple DrawerLayout
The following code shows a simple drawer-layout usage.
var win = Ti.UI.createWindow();
var leftView = Ti.UI.createView({ backgroundColor:'red' });
var centerView = Ti.UI.createView({ backgroundColor:'yellow' });
var rightView = Ti.UI.createView({ backgroundColor:'orange' });
var drawer = Ti.UI.Android.createDrawerLayout({
leftView: leftView,
centerView: centerView,
rightView: rightView
});
var btn = Ti.UI.createButton({ title: 'RIGHT' });
btn.addEventListener('click', function() {
drawer.toggleRight();
});
centerView.add(btn);
win.addEventListener('open', function(){
var activity = win.activity,
actionBar = activity.actionBar;
if (actionBar) {
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = function() {
drawer.toggleLeft();
};
}
});
win.add(drawer);
win.open();
# Alloy DrawerLayout example
The following code shows an Alloy version of the drawer-layout.
<Alloy>
<Window class="container">
<ActionBar platform="android" displayHomeAsUp="true" onHomeIconItemSelected="onClickDrawer" />
<DrawerLayout id="drawer" platform="android">
<LeftView>
<View backgroundColor="#fff"></View>
</LeftView>
<CenterView>
<View>
<Label text="Center view" />
</View>
</CenterView>
</DrawerLayout>
</Window>
</Alloy>
function onClickDrawer(e){
$.drawer.toggleLeft();
}
$.index.open();
# Properties
# drawerIndicatorEnabled
Determine the drawer indicator status
Default: true
# drawerLockMode
Get or set the drawerLockMode
Default: Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNDEFINED
# isRightVisible
Determine whether the right drawer is visible
Default: false
# leftDrawerLockMode
Get or set lock mode for the left drawer
Default: Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNDEFINED
# rightDrawerLockMode
Get or set lock mode for the right drawer
Default: Titanium.UI.Android.DrawerLayout.LOCK_MODE_UNDEFINED
# toolbar CREATION ONLY
A Toolbar instance to use as a toolbar.
Allows using a [Toolbar]Titanium.UI.Toolbar as a toolbar in the DrawerLayout, exposing [Toolbar's]Titanium.UI.Toolbar properties and methods for a further customization.
This Toolbar instance is automatically set to be used as a default ActionBar.
# toolbarEnabled
Determine whether to enable the toolbar.
This property is ignored if the used theme provides a default ActionBar.
Default: true
# Methods
# interceptTouchEvent
Disallow touch events on a specific view.
Parameters
Name | Type | Description |
---|---|---|
view | Titanium.UI.View | View to intercept touch events. |
disallowIntercept | Boolean | Whether to disallow the interception of touch events. |
Returns
- Type
- void
# Events
# open
Fired when the drawer view is opened.
Properties
Name | Type | Description |
---|---|---|
drawer | String | Contains the drawer frame type. Either |
source | Object | Source object that fired the event. |
type | String | Name of the event fired. |
bubbles | Boolean | True if the event will try to bubble up if possible. |
cancelBubble | Boolean | Set to true to stop the event from bubbling. |
# close
Fired when the drawer view is closed.
Properties
Name | Type | Description |
---|---|---|
drawer | String | Contains the drawer frame type. Either |
source | Object | Source object that fired the event. |
type | String | Name of the event fired. |
bubbles | Boolean | True if the event will try to bubble up if possible. |
cancelBubble | Boolean | Set to true to stop the event from bubbling. |
# change
Fired when the motion state of the drawer view changes.
Properties
Name | Type | Description |
---|---|---|
drawer | String | Contains the drawer frame type. Either |
state | Number | The current drawer state. |
idle | Boolean | Whether or not the drawer is currently idle. |
dragging | Boolean | Whether or not the drawer is currently dragging. |
settling | Boolean | Whether or not the drawer is currently settling. |
source | Object | Source object that fired the event. |
type | String | Name of the event fired. |
bubbles | Boolean | True if the event will try to bubble up if possible. |
cancelBubble | Boolean | Set to true to stop the event from bubbling. |
# slide
Fired when the drawer view changes it's position.
Properties
Name | Type | Description |
---|---|---|
drawer | String | Contains the drawer frame type. Either |
offset | Number | The current drawer offset. |
source | Object | Source object that fired the event. |
type | String | Name of the event fired. |
bubbles | Boolean | True if the event will try to bubble up if possible. |
cancelBubble | Boolean | Set to true to stop the event from bubbling. |
# Constants
# LOCK_MODE_LOCKED_CLOSED
Use with drawerLockMode to specify the drawer is locked closed.
# LOCK_MODE_LOCKED_OPEN
Use with drawerLockMode to specify the drawer is locked opened.
# LOCK_MODE_UNDEFINED
Use with drawerLockMode to specify the drawer is reset to default lock state.
# LOCK_MODE_UNLOCKED
Use with drawerLockMode to specify the drawer is unlocked.