android - Change background color of programmatically created radio button


Keywords:android 


Question: 

I used various method but I couldn't find a way to change color of a RadioButton that's created programmatically. Is there any other way than using a background Image? with minSDKVersion is 21. The below way I'm creating my RadioButton.

RadioButton radio = new RadioButton(co);


2 Answers: 

To change RadioButton button color programmatically use this. because your minSdk is 21. You can use setButtonTintList this way.

RadioButton raPrivate = new RadioButton(co);
int textColor = Color.parseColor(#000000);
raPrivate.setButtonTintList(ColorStateList.valueOf(textColor));
 

Try this if you want to change background color of Radio Button:

 radioButton.setBackgroundColor(Color.GREEN);