Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How can I change the text size of dynamically created radio buttons?

I didn't find any solution regarding this problem in stack overflow that's why I am posting it here. I am creating radio buttons dynamically as follows.

RadioButton rb;

//generating radio buttons
for (int i = 0; i < 5; i++) {
    rb = new RadioButton(this);
    rb.setText(question.getOptions().get(i));
    rb.setTextColor(getResources().getColor(R.color.rbTextColor));
    rb.setId(i);
    rg.addView(rb);
}

It's working perfectly fine but now I want to change the text size of the text of radio buttons through code which should be something like this an per my poor understanding.

rb.setTextSize(20);

but it's now working because radio button does not have this property. So please help me out how can I change the size of the text of the radio buttons in android?

Any help would be greatly appreciated.

Thanks,

momersaleem

like image 392
momersaleem Avatar asked Jan 27 '15 19:01

momersaleem


1 Answers

You use text appearance like so:

    RadioButton rb;

    //generating radio buttons
    for (int i = 0; i < 5; i++) {
        rb = new RadioButton(context);
        rb.setText("");
        rb.setTextColor(getResources().getColor(R.color.rbTextColor));
        rb.setId(i);
        rb.setTextAppearance(context, android.R.style.TextAppearance_Large);
    }
like image 91
Kristy Welsh Avatar answered Sep 21 '22 00:09

Kristy Welsh