SDK: 4.1.5
Device: Fenix 7 in simulator
References:
https://forums.garmin.com/developer/connect-iq/f/discussion/306285/menu2-a-lot-of-questions/1482231#1482231
|https://forums.garmin.com/developer/connect-iq/f/discussion/306285/menu2-a-lot-of-questions/1482431#1482431
https://forums.garmin.com/developer/connect-iq/f/discussion/306285/menu2-a-lot-of-questions/1482431#1482431
Code that doesn't work:
var menu = new WatchUi.Menu2({:title => "Wind Surf"}); var appIcon = WatchUi.loadResource(Rez.Drawables.LauncherIcon); menu.addItem(new WatchUi.IconMenuItem("Sails", null, "item_sail", appIcon, null));
Error: Unhandled Exception
Exception: UnexpectedTypeException: Unexpected icon type, expected Drawable
Code that works:
//... menu.addItem( new WatchUi.IconMenuItem( "Sails", null, "item_sail", new CustomIcon(Rez.Drawables.LauncherIcon), null ) ); // ... } // end of function // ... } // end of class class CustomIcon extends WatchUi.Drawable { var bitmapResource = null; public function initialize(resourceId) { Drawable.initialize({}); bitmapResource = WatchUi.loadResource(resourceId); } public function draw(dc as Dc) as Void { dc.setColor(Graphics.COLOR_TRANSPARENT, Graphics.COLOR_TRANSPARENT); dc.clear(); dc.drawBitmap(0, 0, bitmapResource); } }
Documentation:
initialize(label as Lang.String, subLabel as Lang.String or Null, identifier, icon as Graphics.BitmapType or WatchUi.Drawable, options as { :alignment as MenuItem.Alignment } or Null)