Skip to content Skip to sidebar Skip to footer

Android Checkboxes Added By Code Don't Have The Right Appearance?

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

Solution 1:

AppCompat replaces the default widgets with tinted, consistent styles, as mentioned in the Android Support Library 22.1 blog post:

This is done automatically when inflating layouts - replacing Button with AppCompatButton, TextView with AppCompatTextView, etc. to ensure that each could support tinting.

If you'd like to create these programmatically, you can use AppCompatCheckBox in place of Checkbox in your code, passing in your current Context such as your AppCompatActivity.

Note: it is very important to not use getApplicationContext() as it does not have the styling information required.

Solution 2:

Use cb.setButtonDrawable(R.drawable.cbOutline); where "cbOutline" is your drawable for the checkboxes outline you defined in your XML.

Post a Comment for "Android Checkboxes Added By Code Don't Have The Right Appearance?"