Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating checkbox using titanium alloy

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,
});
like image 268
user2274163 Avatar asked Apr 30 '26 17:04

user2274163


1 Answers

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
}
like image 155
Josiah Hester Avatar answered May 03 '26 08:05

Josiah Hester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!