Android 钛和安卓:使用文本字段内的按钮
是否可以创建一个包含按钮的文本字段?我找到了属性rightButton和leftButton,但是使用Android(emulator)不起作用。还有其他选择吗 这是使用的代码:Android 钛和安卓:使用文本字段内的按钮,android,mobile,titanium,Android,Mobile,Titanium,是否可以创建一个包含按钮的文本字段?我找到了属性rightButton和leftButton,但是使用Android(emulator)不起作用。还有其他选择吗 这是使用的代码: var rightButton1 = Titanium.UI.createButton({ color:'#fff', width:25, height:25, right:10, backgroundImage:'plus.png', backgroundSelecte
var rightButton1 = Titanium.UI.createButton({
color:'#fff',
width:25,
height:25,
right:10,
backgroundImage:'plus.png',
backgroundSelectedImage:'plus.png',
backgroundDisabledImage: 'plus.png'
});
rightButton1.addEventListener('click',function()
{
Titanium.UI.createAlertDialog({
title:'Button clicked',
message:'Button clicked'
}).show();
});
var textField3 = Titanium.UI.createTextField({
color:'#336699',
width:"auto",
height:"auto",
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
rightButton:rightButton1
});
提前感谢。据《每日电讯报》报道,这是iPhone目前唯一的功能
if(Titanium.Platform.name == 'iPhone OS') {
data.push({title:'Buttons on Textfields', hasChild:true, test:'../examples/textfield_buttons.js'});
}
但是,我不明白为什么你不能通过创建一个视图并将按钮放在文本字段的顶部来伪造它,因为Titanium.UI.Android
支持zIndex
很好,并且focus
事件可以切换按钮的可见性
var view = Ti.UI.createView();
var textField = Ti.UI.createTextField({
// cordinates using top, right, left, bottom
zIndex: 1
});
var button = Ti.UI.createButton({
// cordinates using top, right, left, bottom
visible: false,
zIndex: (textField.zIndex + 1)
});
view.add(textField);
Ti.UI.currentWindow.add(button);
Ti.UI.currentWindow.add(view);
// you only need the listeners if you want to hide and show the button
textField.addEventListener('focus', function(e) {
button.show();
});
textField.addEventListener('blur', function(e) {
button.hide();
});
请发布所有相关代码。@brian huenefeld谢谢。非常有用的答案。