开发者

Titanium and Android: Using button inside textfield

Is it possible to make a textfield with buttons inside? I found the properties rightButton and leftButton, but using Android (emulator) does not work. Is there another alternative?

That is the used code:

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

Thanks in advance.


According to the KitchenSink it's an iPhone only function currently.

if(Titanium.Platform.name == 'iPhone OS') {
    data.push({title:'Buttons on Textfields', hasChild:true, test:'../examples/textfield_buttons.js'});
}

However I don't see why you couldn't fake this by creating a view and placing the button on top of the textField because Titanium.UI.Android supports zIndex just fine and the focus event to toggle the visibility of the button.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜