属性 | 说明 |
---|---|
RadioGroup | 合并RadioButton |
android:checked | 设置默认选项 |
android:button=“@null” | 去除圆圈 |
1.选择全局RelativeLayout
2.设置RadioGroup布局方式(vertical、horizontal)
3.是否去除圆圈
4.是否设置默认选项
5.drawable设置点击效果
public class RadioButtonActivity extends AppCompatActivity {
private RadioGroup mRg1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_button);
mRg1 = (RadioGroup) findViewById(R.id.rg_1);
mRg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
RadioButton radioButton = radioGroup.findViewById(checkedId);
Toast.makeText(RadioButtonActivity.this,radioButton.getText(),Toast.LENGTH_SHORT).show();
}
});
}
}