此代码创建一个单选按钮组。你可以在你的 Alloy 项目中使用它,尽管它不是一个 Alloy Widget。此链接有一个完整的经典示例。
https://github.com/yozef/TiRadioButtonGroup
由于它不是 Alloy 小部件,我相信您需要通过 index.js 文件来完成所有这些操作。
在项目的 app 文件夹中。将 radioButtonActive.png 和 radioButton.png 复制到 assets/iphone 和 assets/android。
在您的 index.xml 文件中,我通常会执行以下操作:
<Alloy>
<Window class="container">
<View id="radioView" />
</Window>
</Alloy>
index.js
var radioButton = require('tiRadioButton');
var radioGroup = radioButton.createGroup({
groupId:1,
width:119,
height:34,
layout:'horizontal',
radioItemsValue:['One', 'Two', 'Three'],
radioItemsPadding:10,
radioItemsBackgroundSelectedImage:'radioButtonActive.png',
radioItemsBackgroundImage:'radioButton.png',
radioItemsWidth:33,
radioItemsHeight:34
});
var headline3 = Ti.UI.createLabel({
text:'Layout: vertical',
color:'#fff',
font:{fontSize:20,fontWeight:'Bold'},
shadowColor:'#000',
shadowOffset:{x:1,y:1},
top:10,
textAlign:'center'
});
var button = Ti.UI.createButton({
title:'Get value'
});
button.addEventListener('singletap', function(e) {
alert("Horizontal radioGroup selectedIdx: " + radioGroup.selectedValue);
});
$.radioView.add(radioGroup);
$.radioView.add(button);
$.index.open();
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000"
}