Dhinakar
Dhinakar

Reputation: 4151

How to change the default circle color of the radiobutton in android by changing in the code itself without using xml

i need to change the default circle color of radiobutton as like below sample

             rdbtn = new RadioButton(this);
            rdbtn.setId(i);
            rdbtn.setText(ansList.getJSONObject(i).getString("Answer"));
            rdbtn.setTextColor(Color.DKGRAY);
            rdbtn.setTextSize(14);

Like this i need to change the circle color. Is there any way please suggest. I dont need custom xml

Upvotes: 0

Views: 1900

Answers (2)

Santhosh
Santhosh

Reputation: 1867

pass selector dynamically as StateListDrawable makes a number of graphic images to a single Drawable as

  rdbtn = (RadioButton) findViewById(R.id.radioButton1);
  StateListDrawable stateListDrawable=new StateListDrawable();
  stateListDrawable.addState(new  int[]{android.R.attr.state_pressed},getResources().getDrawable(id1));
  stateListDrawable.addState(new int[]{android.R.attr.state_checkable},getResources().getDrawable(id2));
   ...
   rdbtn.setButtonDrawable(stateListDrawable);

Upvotes: 0

Sucho
Sucho

Reputation: 321

I have never set colour to the radio button, But I have set Drawable to it. See, if you can use this somehow-

rb.setButtonDrawable(R.drawable.'you image here');

Upvotes: 1

Related Questions