1.布局
<RadioGroup
android:id="@+id/rg"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:buttonTint="@color/colorAccent"
android:text="是"
android:id="@+id/ok"
style="@style/xgmmcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingTop="5dip"
android:paddingRight="5dip"
android:paddingBottom="5dp"
android:textColor="@color/black" />
<RadioButton
android:buttonTint="@color/colorAccent"
android:checked="true"
android:text="否"
android:id="@+id/no"
style="@style/xgmmcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingTop="5dip"
android:paddingRight="5dip"
android:paddingBottom="5dp"
android:textColor="@color/black" />
</RadioGroup>
2.代码使用
rg = findViewById(R.id.rg);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkid) {
switch (checkid){
case R.id.ok:
Toast.makeText(JiangKangDaKaActivity.this,"是",Toast.LENGTH_SHORT).show();
break;
case R.id.no:
Toast.makeText(JiangKangDaKaActivity.this,"是",Toast.LENGTH_SHORT).show();
break;
}
}
});
3.通过属性改变radiobutton选中时的颜色(注:在radiobutton属性中添加)
android:buttonTint="@color/colorAccent"
网友评论