美文网首页
Android RadioGroup RadioButton

Android RadioGroup RadioButton

作者: 菜鸟考官 | 来源:发表于2018-12-14 10:52 被阅读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)
        }

    相关文章

      网友评论

          本文标题:Android RadioGroup RadioButton

          本文链接:https://www.haomeiwen.com/subject/jbmwhqtx.html