Android 单选组合框

Android RadioGroup和RadioButton案例及详解 https://my.oschina.net/amigos/blog/59261

RadioButton默认的样式(Android-25)

在Android/sdk/platforms/android-25/data/res/values/styles.xml:374(以前的版本好像带有item name="background"属性)

在Android/sdk/platforms/android-25/data/res/values/themes.xml:154中

@drawable/btn_radio
在Android/sdk/platforms/android-25/data/res/drawable/btn_radio.xml


    
    
          
    
    

    
    

    
    

如果需要自定义RadioButton的样式,可以采用

radioButton.setButtonDrawable(null); //去除RadioButton前面的圆点
radioButton.setBackgroundResource(R.drawable.XXX);

RadioGroup动态添加RadioButton(实现水平指示点)

//RadioGroup实现水平指示点
private RadioGroup mRadioGroup = (RadioGroup) findViewById(R.id.XXX);
mRadioGroup.removeAllViews();
for (int i = 0; i < COUNT; i++) { //COUNT个指示点
	RadioButton radioButton = new RadioButton(mContext);
	radioButton.setId(i);
	RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(width, height);//radioButton的宽高
	lp.gravity = Gravity.CENTER;
	radioButton.setButtonDrawable(null);
	radioButton.setBackgroundResource(R.drawable.XXX);//radioButton的自定义样式
	if (i == 0) {
	   radioButton.setChecked(true);
	} else {
	   lp.setMargins(left, 0, 0, 0);//两个radioButton之间的距离
	}
	radioButton.setLayoutParams(lp);
	mRadioGroup.addView(radioButton);
}





你可能感兴趣的:(Android)