Titanium 如何在文本字段上动态更改背景图像

Titanium 如何在文本字段上动态更改背景图像,titanium,titanium-mobile,Titanium,Titanium Mobile,我做以下几点 当我点击文本字段时,我会显示一个选择器,并更改文本字段的背景图像 当这个人完成了选择器(他们点击“完成”),我将文本字段背景改回白色 当我再次单击文本字段时,即使选择器出现,背景图像也不会改变 我能做什么?我想要它,这样每当我点击文本字段并出现选择器时,它就会一直变为绿色背景。然后当我轻按它的时候变回白色,选择器消失了 tf1.addEventListener('focus', function(e) { Titanium.API.info('Triggered focus

我做以下几点

当我点击文本字段时,我会显示一个选择器,并更改文本字段的背景图像

当这个人完成了选择器(他们点击“完成”),我将文本字段背景改回白色

当我再次单击文本字段时,即使选择器出现,背景图像也不会改变

我能做什么?我想要它,这样每当我点击文本字段并出现选择器时,它就会一直变为绿色背景。然后当我轻按它的时候变回白色,选择器消失了

tf1.addEventListener('focus', function(e) {
    Titanium.API.info('Triggered focus on date txtField');

    tf1.setBackgroundImage('../images/selected.gif');

    Titanium.API.info(tf1.backgroundImage);

    var winDatePicker1 = Titanium.UI.currentWindow;

    var minDate = new Date();
    minDate.getFullYear();
    minDate.getMonth();
    minDate.getDate();

    var maxDate = new Date();
    maxDate.setFullYear(2018);
    maxDate.setMonth(9);
    maxDate.setDate(30);

    var datePicker = Ti.UI.createPicker({
        type : Ti.UI.PICKER_TYPE_DATE_AND_TIME,
        minDate : minDate,
        maxDate : maxDate,
        bottom : 0,
        minuteInterval : 10
    });

    var tview = Ti.UI.createView({
        height : '100%',
        width : '100%',
        top : 0,
        backgroundColor : 'transparent'
    });

    var done1 = Ti.UI.createImageView({
        title : '',
        width : 80,
        right : 12,
        height : 40,
        image : '../images/done.gif',
    });

    var toolbar1 = Ti.UI.createView({
        height : 43,
        backgroundImage : '../images/toolbar.gif',
    });

    toolbar1.add(done1);

    done1.addEventListener('click', function() {
        tf1.backgroundImage = '';
        toolbar1.hide();
        datePicker.hide();
        tview.hide();
    });

    tview.addEventListener('click', function() {
        toolbar1.hide();
        datePicker.hide();
        tview.hide();
    });

    // turn on the selection indicator (off by default)
    datePicker.selectionIndicator = true;

    datePicker.addEventListener('change', function(e) {

        Titanium.API.info('E value = ' + e.value);

        var pickerDate = e.value;

        var day = pickerDate.getDate();
        day = day.toString();

        if (day.length < 2) {
            day = '0' + day;
        }

        var month = pickerDate.getMonth();
        month = month + 1;
        month = month.toString();

        if (month.length < 2) {
            month = '0' + month;
        }

        var year = pickerDate.getFullYear();
        var hr = pickerDate.getHours();
        var min = pickerDate.getMinutes();

        if (hr < 10) {
            hr = '0' + hr;
        }

        if (min < 10) {
            min = '0' + min;
        }

        var datestr = '';

        if (hr >= 12) 
        {
            datestr += ' ' + (hr == 12 ? hr : hr - 12) + ':' + min + ' PM';
        } else {
            datestr += ' ' + hr + ':' + min + ' AM';
        }

        var newdate = month + "/" + day + "/" + year + datestr;

        Titanium.API.info('converted value = ' + newdate);

        tf1.setValue(newdate);

    });

    tview.add(datePicker);
    tview.add(toolbar1);

    winDatePicker1.add(tview);

    winDatePicker1.show({
        view : tf1,
        animated : true
    });

});
tf1.addEventListener('focus',函数(e){
Titanium.API.info(“触发关注日期txtField”);
tf1.setBackgroundImage('../images/selected.gif');
Titanium.API.info(tf1.backgroundImage);
var winDatePicker1=Titanium.UI.currentWindow;
var minDate=新日期();
minDate.getFullYear();
minDate.getMonth();
getDate();
var maxDate=新日期();
maxDate.setFullYear(2018年);
maxDate.setMonth(9);
maxDate.setDate(30);
var datePicker=Ti.UI.createPicker({
类型:Ti.UI.PICKER\u类型\u日期和时间,
minDate:minDate,
maxDate:maxDate,
底部:0,
分钟间隔:10
});
var tview=Ti.UI.createView({
高度:“100%”,
宽度:“100%”,
排名:0,
背景颜色:“透明”
});
var done1=Ti.UI.createImageView({
标题:“”,
宽度:80,
右:12,
身高:40,
图像:'../images/done.gif',
});
var toolbar1=Ti.UI.createView({
身高:43,
背景图像:'../images/toolbar.gif',
});
工具栏1.添加(done1);
done1.addEventListener('click',function(){
tf1.backgroundImage='';
工具栏1.hide();
datePicker.hide();
tview.hide();
});
tview.addEventListener('单击',函数()){
工具栏1.hide();
datePicker.hide();
tview.hide();
});
//打开选择指示器(默认情况下关闭)
datePicker.selectionIndicator=true;
datePicker.addEventListener('change',函数(e){
钛.原料药信息('E值='+E值);
var pickerDate=e.值;
var day=pickerDate.getDate();
day=day.toString();
如果(日长<2){
天='0'+天;
}
var month=pickerDate.getMonth();
月=月+1;
month=month.toString();
如果(月长<2){
月份='0'+月份;
}
var year=pickerDate.getFullYear();
var hr=pickerDate.getHours();
var min=pickerDate.getMinutes();
如果(小时<10){
人力资源='0'+人力资源;
}
如果(最小值<10){
最小值='0'+最小值;
}
var datestr='';
如果(hr>=12)
{
datestr+=''+(hr==12?hr:hr-12)+':'+min+'PM';
}否则{
datestr+=''+hr+':''+min+'AM';
}
var newdate=month+“/”+day+“/”+year+datestr;
Titanium.API.info('转换值='+新日期);
tf1.设置值(新日期);
});
tview.add(日期选择器);
tview.add(工具栏1);
winDatePicker1.添加(tview);
winDatePicker1.show({
视图:tf1,
动画:真的
});
});
make setVisible(true) or setVisible(false)

show() and hide() will not give proper toggle at some conditions.