RadioButton(1)

齐雅畅
2023-12-01

安卓控件-RadioButton

常用属性

属性说明
RadioGroup合并RadioButton
android:checked设置默认选项
android:button=“@null”去除圆圈

自定义样式

1.选择全局RelativeLayout

2.设置RadioGroup布局方式(vertical、horizontal)

3.是否去除圆圈

4.是否设置默认选项

5.drawable设置点击效果

监听事件

setOnCheckedChangeListener方法

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();
            }
        });
    }
}
 类似资料: