'Is it possible to set color and size attributes of programmatically created radio buttons?
In an activity java file, we created radio buttons dynamically in a for loop to display when the activity is run. However, because they are dynamically created, we are am unable to edit their properties (such as color, text size, etc) as in a typical xml file. How can we set such properties (color, size, etc...) programmatically?
public void PrintGames(ArrayList<String> games,String league ) {
setContentView(R.layout.activity_api_connection_test);
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
RadioGroup rg2 = new RadioGroup(this);
rg2.setOrientation(LinearLayout.VERTICAL);
//ArrayList<RadioButton> buttons = new ArrayList<RadioButton>();
for (int i = 0; i < games.size(); i++) {
RadioGroup rg = new RadioGroup(this);
rg.setOrientation(LinearLayout.VERTICAL);
RadioButton button = new RadioButton(this);
RadioButton button2 = new RadioButton(this);
button.setText("Home");
button2.setText("Away");
button.setId(View.generateViewId());
button2.setId(View.generateViewId());
TextView textbutton = new TextView(this);
rg.addView(textbutton);
rg.addView(button);
rg.addView(button2);
textbutton.setText("" + games.get(i));
rg2.addView(rg);
}
layout.addView(rg2);
if (games.isEmpty()) {
TextView nogames = new TextView(this);
nogames.setText("No Games today");
layout.addView(nogames);
} else {
Button submit = new Button(this);
submit.setText("Submit");
layout.addView(submit);
//on click listner
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Store(rg2,league);
}
});
}
}
I found some threads saying its not possible for radio buttons and there was suggestions to create vector asset drawables, but many of those threads are outdated (2011), and I have a feeling its possible now with the advanced studio we have.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
