我一直在努力解决这个问题。似乎是一个半虫。
如果将leftButton或rightButton添加到textField,如下所示:
var leftButton = Ti.UI.createButton({
image: 'someImage.png'
})
var textField = Ti.UI.createTextField({
leftButton: leftButton,
leftButtonMode: Ti.UI.INPUT_BUTTONMODE_ALWAYS,
leftButtonPadding: 100
})
...那么你就不会看到你的按钮了。为什么呢?
答案 0 :(得分:1)
此代码可能存在2个问题。 1-检查分配给按钮的图像路径..? (高度宽度) 出于测试目的,尝试使用任何系统按钮,看看它是否出现。?
var leftButton = Titanium.UI.createButton({
style:Titanium.UI.iPhone.SystemButton.DISCLOSURE
});
2-秒问题可能是左边的填充 尝试使用它而不用填充,然后看看会发生什么。
答案 1 :(得分:1)
var win = Titanium.UI.createWindow({
title:"Configuring text field and text area keyboard types",
backgroundColor:"#347AA9",
exitOnClose:true
});
//These buttons will appear within the text field
var clearButton = Titanium.UI.createButton({
title:"Clear",
height:24,
width:52
});
var submitButton = Titanium.UI.createButton({
title:"Submit",
height:24,
width:60
});
var textField = Titanium.UI.createTextField({
top:"25%",
height:35,
width:600,
backgroundColor:"#ffffff",
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
hintText:"Type something",
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
leftButton:clearButton,
rightButton:submitButton
});
clearButton.addEventListener("click", function(e){
//Clear the value of the text field
textField.value = "";
});
submitButton.addEventListener("click", function(e){
//Pretend to submit the value of the text field
//Be sure that you've typed something in!
if(textField.value != ""){
alert(textField.value);
}else{
alert("Enter some text");
}
});
//Add an event listener to the window that allows for the keyboard or input keys to be hidden if the user taps outside a text field
//Note: each text field to be blurred would be added below
win.addEventListener("click", function(e){
textField.blur(); // Cause the text field to lose focus, thereby hiding the keyboard (if visible)
});
win.add(textField);
win.open();
答案 2 :(得分:0)
问题出在leftButtonMode属性中。给它任何值,按钮不会显示。如果您不使用此属性,该按钮将显示正常。
对于leftButton,padding属性不是问题。但是如果你在rightButton上使用它,它可能会把你的按钮扔到屏幕外面。我也尝试过负值,但没有成功。
请注意,leftButton和rightButton选项在Android上不起作用。