Reputation: 61
I am new in Titanium alloy and I would like to change my project from titanium default template to alloy. Below is the code for creating a text box in default template. I would like to change this to alloy template.
var checkbox = Ti.UI.createSwitch({
id:'checkbox',
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
});
Upvotes: 3
Views: 3810
Reputation: 2525
You can create the check box like this.
var checkbox = Ti.UI.createSwitch({
style: Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,
title:'Notice Me',
value:true,
width: 300,
left: 18
});
win.add(checkbox);
checkbox.addEventListener('change',function(e){
//function
Ti.API.info('Switch value: ' + checkbox.value);
});
Upvotes: 1
Reputation: 6095
Not hard at all! Try this inside your Alloy XML view markup:
checkbox.xml
<Alloy>
<Switch id="checkbox"/>
</Alloy>
Now we can use the style file to set attributes based on the id.
checkbox.tss
"#checkbox[platform=android]" : {
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX
}
This will set the style to checkbox, also note that I set this to only happen for android. Alternatively, if we wanted every switch to be of the checkbox style we could set this inside app.tss:
"Switch" : {
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX
}
Upvotes: 5