titanium开发教程0204创建开关

1

var win = Titanium.UI.createWindow({
	title:"创建开关",
	backgroundColor:"#FFF",
	exitOnClose:true
});

var switch1 = Titanium.UI.createSwitch({
	top:100,
	value:true, //设置开关的初始值, true 或 false ( 在iOS为1 或 0 , 在Android 是true 或 false )
	titleOn:"你好",
	titleOff:"不好"
});

var results1 = Titanium.UI.createLabel({
	text:"选择1",
	height:40,
	"auto",
	top:160		
});

var PLATFORM = Titanium.Platform.osname;

if(PLATFORM === "android"){
	//在Android, 我们有两种选择 - togglebutton (默认) 和 checkbox
	var switch2 = Titanium.UI.createSwitch({
		top:200,
		value:true, 
		style:Titanium.UI.Android.SWITCH_STYLE_CHECKBOX
	});

	var results2 = Titanium.UI.createLabel({
		text:"选择2",
		height:40,
		"auto",
		top:260
	});
}


switch1.addEventListener("change", function(e){
	results1.text = e.value; 
});

if(PLATFORM === "android"){
	switch2.addEventListener("change", function(e){
		results2.text = e.value; 
	});
}

win.add(switch1);
win.add(results1);

if(PLATFORM === "android"){
	win.add(switch2);
	win.add(results2);
}

win.open();
原文地址:https://www.cnblogs.com/xiaozhanga4/p/2402430.html