Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Icon font MenuItem in ActionBar menu for Titanium SDK
var args = arguments[0] || {};
if(__parentSymbol) {
// recreate menu item
$.getTopLevelViews().length = 0;
__parentSymbol.removeItem(9999);
$.__views.menuItem = __parentSymbol.add(
_.extend(_.pick(args, Alloy.Android.menuItemCreateArgs), {
actionView: $.actionView
})
);
$.__views.menuItem.applyProperties(_.omit(args, Alloy.Android.menuItemCreateArgs.concat(['iconClass'])));
$.menuItem = $.__views.menuItem;
$.addTopLevelView($.__views.menuItem);
} else {
throw "Can't use this controller out of menu";
}
$.iconLabel.applyProperties($.createStyle({
classes : (_.isString(args.iconClass) ? args.iconClass.split(' '): args.iconClass).concat(['actionBarMenuIcon']),
apiName : "Label"
}));
function itemClick(evt) {
$.trigger('click', evt);
}
".actionBarMenuIcon": {
backgroundImage: 'none',
height: Titanium.UI.FILL,
color: "#e2e1d3",
width: 48,
textAlign: Titanium.UI.TEXT_ALIGNMENT_CENTER,
font: {
fontSize: 30
},
backgroundSelectedColor: "rgba(155,155,155,128)"
}
".container": {
width: Titanium.UI.SIZE,
height: Titanium.UI.FILL,
borderWidth: 0
}
<Alloy>
<MenuItem id="menuItem" itemId="9999">
<ActionView>
<View id="actionView" class="container" onClick="itemClick">
<Label id="iconLabel" />
</View>
</ActionView>
</MenuItem>
</Alloy>
".icon-account-plus": {
font: {
fontFamily: "materialdesignicons-webfont"
},
text: "\uf10f"
}
"#menuItemAccountPlus": {
showAsAction: Titanium.Android.SHOW_AS_ACTION_ALWAYS,
iconClass: "icon-account-plus"
}
<Alloy>
<Window>
<Menu id="menu">
<Require src="actionBarMenuItem" id="menuItemAccountPlus" onClick="doSelectContact" />
</Menu>
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment