Android RadioGroup RadioButton
2018-12-14 本文已影响0人
菜鸟考官
image.png
shoesRadioGroup = radioGroup_type_shoes
for (i in 0 until shoesList.size) {
var radiobutton = RadioButton(shoesRadioGroup.context)
radiobutton.id = i
val a: Bitmap? = null
radiobutton.buttonDrawable = BitmapDrawable(a)
val mButtonLayoutParams =
RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
mButtonLayoutParams.setMargins(DensityUtils.dp2px(context, 16F), 0, 0, 0)
radiobutton.layoutParams = mButtonLayoutParams
radiobutton.text = shoesList[i]
//设置选中未选中颜色 使用getColorStateList
radiobutton.setTextColor(context!!.resources.getColorStateList(R.color.select_radiobutton))
if (i == 0) {
//默认选中第一个
radiobutton.isChecked = true
}
shoesRadioGroup.addView(radiobutton)
}