ricardoalcocer / actionbarextras

Titanium Android Native Module that exposes ActionBar features not exposed by the Titanium SDK
MIT License
149 stars 60 forks source link

Custom view in action bar? #101

Closed trkfabi closed 8 years ago

trkfabi commented 8 years ago

Is it possible to add a custom view (Ti.UI.view) to the actionbar? I want to show menuItem icons on the right and show a view on the left containing 2 labels that will be dynamically updated from time to time (i.e.: an account balance that gets updated with every $ movement).

Thanks

manumaticx commented 8 years ago

Hi @trkfabi

sorry for the late reply.

Have you tried this with Titanium.Android.MenuItem.actionView?

Something like this:

/**
 * Android callback for {Ti.UI.Window} open event
 */
function onOpen() {

  var activity = $.index.getActivity();

  if (activity) {

    var actionBar = activity.getActionBar();

    activity.onCreateOptionsMenu = function(e) {
      e.menu.clear();

      e.activity = activity;
      e.actionBar = actionBar;

      var actionView = Ti.UI.createView({
          backgroundColor: "white",
          layout: 'vertical'
      });

      actionView.add(Ti.UI.createLabel({text: "foo", color: '#000'}));
      actionView.add(Ti.UI.createLabel({text: "123", color: '#000'}));

      var menuItem = e.menu.add({
        title : "test",
        actionView: actionView,
        showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS
      });
      menuItem.expandActionView();

    };
    activity.invalidateOptionsMenu();
  };
}