Issue
I've got a really basic app in which I'm trying to insert dynamic checkboxes, and I can get them to appear, but they're not showing with the correct styling.
See below - Foo is in the LinearLayout by definition; Bar is being added programmatically. Foo is showing with a grey box for the check, Bar is showing with a white box.
Here's the code that's creating these:
for (Integer i=0; i < arArray.length;i++) {
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText("Bar");
cb.setTextColor(getResources().getColor(android.R.color.black));
cb.setOnCheckedChangeListener(clListener);
llDeckChecks.addView(cb);
}
I've tried setting the drawable to some android.R.drawable types, but nothing matches the Foo checkbox, so I'm entirely stumped at this point.
Solution
You should use the activity context to create the button instead of the application context. If you use getApplicationContext()
it does not extend ContextThemeWrapper
.
Try changing
CheckBox cb = new CheckBox(getApplicationContext());
to
CheckBox cb = new CheckBox(YourActivity.this); // or getActivity() if in a fragment.
Answered By - user4399184
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.