【问题标题】:Titanium and Android: Using button inside textfieldTitanium 和 Android:在文本字段中使用按钮
【发布时间】:2011-08-28 05:12:11
【问题描述】:

是否可以制作一个带有按钮的文本字段?我找到了属性 rightButton 和 leftButton,但是使用 Android(模拟器)不起作用。还有其他选择吗?

这是使用的代码:

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

提前致谢。

【问题讨论】:

  • 请发布您所有的相关代码。

标签: android mobile titanium


【解决方案1】:

根据KitchenSink,目前这是iPhone独有的功能。

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

但是我不明白为什么你不能通过创建view 并将按钮放在textField 上来伪造它,因为Titanium.UI.Android 支持zIndex 很好,focus 事件切换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();
});

【讨论】:

  • @brian-huenefeld 谢谢。非常有用的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多