`
longgangbai
  • 浏览: 7273129 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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();

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics