android - 钛和安卓 : Using button inside textfield

标签 android mobile titanium

是否可以制作一个带有按钮的文本框?我找到了属性 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
});

提前致谢。

最佳答案

根据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 很好地支持 zIndexfocus 事件来切换 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();
});

关于android - 钛和安卓 : Using button inside textfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6047828/

相关文章:

javascript - 从 Titanium Mobile 中的 TableView 获取表行

android - 如何开发Android应用程序?

android - 尝试在空对象引用上调用虚拟方法 'com.orm.Database com.orm.SugarApp.getDatabase()'

android - 如何在 Android 应用程序中添加额外的菜单项?

android - 调用 onActivityResult 后 Activity 关闭

html - 移动 HTML5 框架 - Jquery 移动

mobile - 离线移动网站

eclipse-plugin - "File is not a valid JSHint library"尝试将最新版本的 jshint 与 eclipse 插件 (Titanium) 一起使用时

java - Android 4.3 启动 Activity 时 native 崩溃

android - 如何配置 Trigger.IO 以将 Intel Atom x86 目标用于我的 Android 虚拟设备?