Android CheckBox Programmatic Style

I have a class that extends Activity and adds some View elements programmatically.

CheckBox checkBox = new CheckBox(this, null, android.R.style.Widget_CompoundButton_Star);

      

I would like to install some Android SDK style checkBoxes. I don't see any mark after I set its style for this Widget_CompoundButton_Star. While this SDK style seems to work when directly hosted in xml.

Am I missing something? thank

// As Pragniani said. Usage android.R.attr.starStyle

works.

+3


source to share


2 answers


I came here looking for CheckBox styling instead of Drawable and I find a different solution. But hey! Let me share my solution with the future.

Instead:

CheckBox cb = new CheckBox(this, null, R.style.yourstyle);

      



Using:

CheckBox cb = new CheckBox(this);
cb.setTextAppearance(this, R.style.yourstyle);

      

Hope this helps resolve the topic of the question!

+2


source


You can set the style for the view programmatically using ContextThemeWrapper.



CheckBox mCheckBox = new CheckBox(new ContextThemeWrapper(context, R.style.MyCheckBox));

      

+5


source







All Articles