Titanium实现Menu键相关菜单实现

Titanium实现Menu键相关菜单实现

 

 

Titanium代码实现如下:

 

 

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

var activity = Ti.Android.currentActivity;
//
// create base UI tab and root window
//
var win = Titanium.UI.createWindow({  
    title:'Titanium Android ContextMenu使用'
});

win.backgroundColor = 'white';

var b1 = Ti.UI.createButton({
	title : '打开窗体',
	height : 'auto',
	width : 'auto'
});

// Here is an example of creating the menu handlers after window creation but before open.
b1.addEventListener('click', function(e) {
	var w = Ti.UI.createWindow({
		backgroundColor : 'blue',
		navBarHidden : false
	});

	w.activity.onCreateOptionsMenu = function(e) {
		var menu = e.menu;
		
		var m1 = menu.add({ title : '关闭窗体' });
		m1.addEventListener('click', function(e) {
			w.close();
		});
	};
	
	w.activity.onPrepareOptionsMenu = function(e) {
		var menu = e.menu;
		
		var mi = menu.findItem(2);
		if (mi == null) {
			mi = menu.add({
				itemId : 2,
				order : 1,
				title : '加载资源'
			});
			mi.addEventListener('click', function(e) {
				Ti.UI.createNotification({ message : "To you and yours." }).show();
			});
		}
	};
	
	var l = Ti.UI.createLabel({
		backgroundColor : 'white', color : 'black',
		width : 'auto', height : 'auto',
		text : '请点击Menu菜单按钮,窗体关闭'
	});
	w.add(l);
	
	w.open({ animated : true});
});

win.add(b1);
win.open();

你可能感兴趣的:(Titanium)