0

我这里有个问题。新窗口在单独的 js 文件中定义。我想在这个窗口中添加一个菜单。所以我使用了以下代码:

var menu = Titanium.UI.Android.OptionMenu.createMenu();

var item1 = Titanium.UI.Android.OptionMenu.createMenuItem({
     title : 'Item 1',
     icon : '/images/item1.png'
});

var item2 = Titanium.UI.Android.OptionMenu.createMenuItem({
     title : 'Refresh',
     icon : '/images/refresh.png'
});
menu.add(item1);
Titanium.UI.Android.OptionMenu.setMenu(menu);

在这样做时,应用程序已经崩溃。谁能帮我解决这个问题?

提前致谢!

注意:使用 Appcelerator 开发 Android 应用程序。

4

1 回答 1

0

always remember Set the menu on the current heavyweight window. To create a heavyweight window, specify one or more of

  1. fullscreen,
  2. navBarHidden,
  3. modal

otherwise you can use you app.js file this is working.... with specify this property.

var menu = Titanium.UI.Android.OptionMenu.createMenu();
var item1 = Titanium.UI.Android.OptionMenu.createMenuItem({
    title : 'Item 1',
    icon : '/images/item1.png'
});

item1.addEventListener('click', function(){
    Ti.UI.createAlertDialog({ title : 'You clicked Item 1'}).show();
});
var item2 = Titanium.UI.Android.OptionMenu.createMenuItem({
    title : 'Refresh',
    icon : '/images/refresh.png'
});
item2.addEventListener('click', function(){
    Ti.UI.createAlertDialog({ title : 'You clicked Refresh'}).show();
});
menu.add(item1);
menu.add(item2);

// Set the menu on the current heavyweight window. A heavyweight window maps to an Android
// Activity. To create a heavyweight window, specify one or more of [**fullscreen**,**navBarHidden**,**modal**] to createWindow.

Titanium.UI.Android.OptionMenu.setMenu(menu);
于 2012-09-07T09:48:14.223 回答