代码:
Bitmap a = null;
//顶部按钮
for (int i = 0; i < topTitles.length; i++) {
RadioButton tempButton = new RadioButton(getActivity());
tempButton.setButtonDrawable(null); // 设置按钮的样式
tempButton.setText(topTitles[i]);
tempButton.setId(i);
tempButton.setTextSize(15);
tempButton.setButtonDrawable(new BitmapDrawable(a));
tempButton.setPadding(30, 0, 30, 0);
tempButton.setBackgroundResource(R.drawable.channel_title_selector);
tempButton.setTextColor(R.drawable.channel_text_color_selector);//不起作用
tempButton.setGravity(Gravity.CENTER);
RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
lp.setMargins(15, 0, 15, 0);//设置RadioButton的边距
mRadioGroup.addView(tempButton, lp);
if (i == 0) {
mRadioGroup.check(tempButton.getId());
}
}