Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9910] Android: Action Items

GitHub Issuen/a
TypeSub-task
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-07-13T17:05:16.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sSprint 2012-14 API, Release 3.0.0
ComponentsAndroid
Labelsapi
ReporterJosh Roesslein
AssigneeJosh Roesslein
Created2012-07-09T15:04:58.000+0000
Updated2012-11-19T12:40:11.000+0000

Description

Add support for [Action Items](http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems). Action items are an extension of the option menu that appear in the action bar displaying a title or a custom view. - Implement the new MenuItem methods for setting the action view, how the action item is displayed (ex: always, if room), and new events (ex: expanded). - May require some build changes to target SDK version 11 or higher. This should still remain compatible (we are not bumping the min. API level) and fallback to using the old style option menus. - Update the documentation to explain how to take advantage of this feature in Honeycomb or later devices.

Action bar menu example

var win = Ti.UI.createWindow({fullscreen: false, backgroundColor: 'red'});

win.activity.onCreateOptionsMenu = function(e) {
  var item = e.menu.add({title: 'Expand'});
  item.showAsAction = Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW;

  var collapseActionButton = Ti.UI.createButton({
    title: 'Collapse'
  });
  collapseActionButton.addEventListener('click', function() {
    item.collapseActionView();
  });
  item.actionView = collapseActionButton;

  item.on('expand', function() {
    alert('Expanded menu item!');
  });
  item.on('collapse', function() {
    alert('Collapsed menu item!');
  });
  item.on('click', function() {
    alert('clicked!');
  });
}

win.open();

Comments

  1. Josh Roesslein 2012-07-11

    To test run the example above. Be sure to test on both a pre-Honeycomb, Honeycomb, and ICS devices. 1. Click the 'Expand' menu item. On pre-Honeycomb devices this will show up in the menu list which is shown via the menu button. On Honeycomb or later you will find this item in the overflow options menu on the action bar (the three vertical dots). 2. After clicking you should see an alert saying "click". On ICS or later you will also see an "expanded" alert dialog. You will also notice on ICS the menu item has expanded into a button view saying "Collapse". 3. On ICS click the "Collapse" action button that was expanded in step 2. It should collapse back into an item in the overflow menu and show an alert saying "collapsed'.
  2. Josh Roesslein 2012-07-11

    Make sure you adjust the "targetSdkVersion" in your Android manifest for the application. This needs to be API level 11 or higher to support the action bar. Also bump it to API level 14 to verify the expand/collapse works for menu items.
  3. Josh Roesslein 2012-07-11

    @Neeraj My PR includes some documentation updates. I will be creating a ticket with Arthur to review the menu documentation and add some additional information.
  4. Andrey Kon 2012-08-31

    I'm new to titanium so maybe my question will look silly but... 1. I wanted to ask if it's possible to remove and add new action items to action bar or to show contextual action bars. 2. Is it possible to add custom views to the left side of action bar zone? 3. What do I have to do to be able to test action items now?
  5. Shyam Bhadauria 2012-11-19

    To test,run the sample app given and observed the below details.(Tested on both a pre-Honeycomb, Honeycomb, and ICS device). 1. Click the 'Expand' menu item. On pre-Honeycomb devices this will show up in the menu list which is shown via the menu button. On Honeycomb or later you will find this item in the overflow options menu on the action bar (the three vertical dots). 2. After clicking you should see an alert saying "click". On ICS or later you will also see an "expanded" alert dialog. You will also notice on ICS the menu item has expanded into a button view saying "Collapse". 3. On ICS click the "Collapse" action button that was expanded in step 2. It should collapse back into an item in the overflow menu and show an alert saying "collapsed'. Devices tested Samsung Galaxy Nexus - Android 4.0.2 Samung GALAXY Tab 620 - Android 3.2 LG-P970 - Android 2.2.2 Titanium SDK:3.0.0.v20121113170203 Titanium  Studio:3.0.0.201211131839

JSON Source