代码设置RadioButton

		// 支出类型
		rgCategorys = (RadioGroup) findViewById(R.id.rg_categorys);
		RadioButton rbGeneral = new RadioButton(getApplicationContext());
		Drawable drawable = this.getResources().getDrawable(R.drawable.selector_project_general); 
		rbGeneral.setText("通用");
		rbGeneral.setTextColor(R.color.black_text);
		rbGeneral.setTextSize(12);
		rbGeneral.setCompoundDrawablesRelativeWithIntrinsicBounds(null, drawable, null, null);  //设置drawableTop
		rbGeneral.setButtonDrawable(android.R.color.transparent);  // 去掉默认圆圈按钮
		rbGeneral.setGravity(Gravity.CENTER);
		rbGeneral.setPadding(0, 5, 25, 0);
		rgCategorys.addView(rbGeneral);

你可能感兴趣的:(代码设置RadioButton)