titaniumtitanium-mobiletitanium-alloytss

How to enable button focus on touchStart?


I have created a button, I need some response from button like, on touch of the button, the button focus should enable like change in background color. How can I do that?

My code is, View:

<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>

Style:

".button":{
    width: '50%',
    top: '25dp',
    borderRadius: 8,
    borderWidth: 1,
    borderColor: '#808080',  
    backgroundGradient: {
        type: "linear",
        startPoint: { x: "0%", y:"0%"},
        endPoint:   { x: "0%", y:"100%"},
        colors: [
            { color: "#4F94CD", offset: 0.0 },
            { color: "#4F94CD", offset: 1.0 }
        ]
    }
}

Controller:

$.proceedButton.addEventListener('touchstart', function() { 
    $.proceedButton.isFocused = true;
  });  

  $.proceedButton.addEventListener('touchend', function() { 
     $.proceedButton.isFocused = false;
  }); 

The above code is not working. Just I need to slight chage in background color while touch of the button.

Any solution!!


Solution

  • As @CodeForFun mentioned you can use backgroundSelectedColor property of button.

    Also following are all the states which can be used by a button in Titanium.

    Hope this would be helpful.

    Edit : An example of usage:

    View :

    <Button class="button" >Proceed</Button>
    

    TSS :

    ".button":{
    width: '50%',
    top: '25dp',
    backgroundSelectedColor : "#4F94CD" //usage
    }