titanium开发教程-02-10创建的文本字段与嵌入的按钮

本文探讨了在iOS平台上实现特定文本输入框功能的方法,包括创建窗口、按钮交互及键盘隐藏逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1该功能无法再android使用,只能在ios上正常显示

 

var win = Titanium.UI.createWindow({
	title:"Configuring text field and text area keyboard types",
	backgroundColor:"#FFF",
	exitOnClose:true
});

//These buttons will appear within the text field
var clearButton = Titanium.UI.createButton({
	title:"Clear",
	height:24,
	width:52
});

var submitButton = Titanium.UI.createButton({
	title:"Submit",
	height:24,
	width:60
});

var textField = Titanium.UI.createTextField({
	top:"25%",
	height:35,
	width:300,
	borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
	hintText:"Type something",
	keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
	leftButton:clearButton,
	rightButton:submitButton
});

clearButton.addEventListener("click", function(e){
	//Clear the value of the text field
	textField.value = "";
});

submitButton.addEventListener("click", function(e){
	//Pretend to submit the value of the text field
	//Be sure that you've typed something in!
	if(textField.value != ""){
		alert(textField.value);	
	}else{
		alert("Enter some text");
	}
});

//Add an event listener to the window that allows for the keyboard or input keys to be hidden if the user taps outside a text field
//Note: each text field to be blurred would be added below
win.addEventListener("click", function(e){
	textField.blur(); // Cause the text field to lose focus, thereby hiding the keyboard (if visible)
});

win.add(textField);

win.open();

转载于:https://www.cnblogs.com/xiaozhanga4/archive/2012/03/17/2402813.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值