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)
}
网友评论