3

I'm creating checkboxes in 2 diffent ways:

1) XML

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="-10dp"
    android:id="@+id/checkBox1" />

2) Java-code

 CheckBox myCheckBox = new CheckBox(this);
 myLayout.addView(myCheckBox);

And the look differently The one from code:

code checked code unchecked

And from XML:

xml checked xml unchecked

Why is that? And how can I make them equal?

UpmostScarab
  • 960
  • 10
  • 29
  • Not sure why that happens exactly but you could try changing the background color for the checkbox by using a drawable – Shrey Oct 07 '15 at 17:43
  • Forget what I said. Take a look at http://stackoverflow.com/questions/5854047/how-to-change-the-color-of-a-checkbox and http://stackoverflow.com/questions/26843098/android-appcompat-v721-0-0-change-material-checkbox-colors – Stephan Branczyk Oct 08 '15 at 00:11

1 Answers1

0

I think it could be because the XML version is newer whereas the Java version draws an older version of a checkbox from an older android. I would suggest just using either Java or Xml for both. Keep them the same

Shanes927
  • 31
  • 6