问题
I have a newbie question: A simple button I've created in Titanium for iPhone refuses to change colors when clicked. Originally I used a button for this function; since it didn't work, I changed to a View, but neither works. Here it how it is set up:
var quifButton = Ti.UI.createView({ // tried this with createButton, as well
top: 44, left: 5, width: 310, height: 42,
backgroundColor: '#333',
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
touchEnabled: true,
borderColor: BOR_DK, borderWidth: 2, borderRadius: 5 });
When I click the Button / View in the iPhone simulator, nothing happens. Any ideas why this doesn't work and how I can make it work?
回答1:
Click is not same than focus. If you want to change color on click, you have to add eventlistener to button or view.
quifButton.addEventListener('click', function(e){
quifButton.backgroundColor = '#fff';
});
*Edit:
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
These are not supported in iOS.
回答2:
This is a limitation in iOS, and is not related to Titanium.
Try this instead for the behaviour you're looking for:
someBtn.addEventListener('touchstart', function() {
someBtn.backgroundColor = 'green';
});
someBtn.addEventListener('touchend', function() {
someBtn.backgroundColor ='blue';
});
回答3:
your code works perfectly fine with me. can you try and let me know if it works or not?
var win1 = Ti.UI.createWindow({
title:'home',
backgroundColor:'white'
});
var button1 = Ti.UI.createButton({
top: 44,
left: 5,
width: 310,
height: 42,
backgroundColor: '#333',
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
touchEnabled: true,
borderWidth: 2,
borderRadius: 5
});
win1.add(button1);
win1.open();
回答4:
can you use backgroundSelectedColor:"#colorcode" in the tss.hope it ll work
回答5:
use backgroundSelectedColor:"color" ,it ll work
来源:https://stackoverflow.com/questions/11709358/titanium-button-not-changing-background-color-when-selected