RadioGroup相關

xml中定義 RadioGroup

<RadioGroup
            android:id="@+id/rgGroup"
            android:layout_marginLeft="@dimen/x18"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
複製代碼

根據服務器數據便利生成RadioButton

classWayList?.forEachIndexed{
            index,value->
            val rb = RadioButton(this)
            val drawable = resources.getDrawable(R.drawable.inner_chx_download_style)
            drawable.bounds=Rect(0,0,Utils.dp2px(18f),Utils.dp2px(18f))
            rb.buttonDrawable = null
            rb.setCompoundDrawables(drawable,null,null,null)
            rb.setBackgroundColor(getColor(R.color.transparent))
            var params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT)
            params.topMargin=Utils.dp2px(21f)
            rb.layoutParams = params
            rb.setTextColor(resources.getColor(R.color.c_6a6c7c))
            rb.text = " "+value.name?:""
            rb.id = index
            rb.isChecked = true
            rgGroup.addView(rb)
        }
複製代碼

drawable 樣式

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_cbx_checked" android:state_checked="true">
    </item>
    <item android:drawable="@drawable/ic_cbx_unchecked" android:state_checked="false" />
    <item android:drawable="@drawable/ic_cbx_unchecked" />
</selector>
複製代碼

資源

相關文章
相關標籤/搜索