0

I am trying to set backgroundColor of CheckBox by code. Its not working on xperia series. same code has tested other deices which is working on samsung and motorola.

CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox);
checkBox.setBackgroundColor(Color.RED);

that is showing black background in xperia only. If I am doing that by xml that is working.

Please let me know if there is any known issue for xperia series.

Thanks in advance.

Saurabh Pareek
  • 7,126
  • 4
  • 28
  • 29

3 Answers3

1

There may be some issue with xperia to setBackgroundColor(). but it works with setDrawingCacheBackgroundColor();

CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox);
checkBox.setDrawingCacheEnabled(true);
checkBox.setDrawingCacheBackgroundColor(Color.RED);
Saurabh Pareek
  • 7,126
  • 4
  • 28
  • 29
0

it has this issue on xperia series ,you can declare the defalut value in layout.xml file,i set the background image ok , android:background="@drawable/test" , then set "setBackgroundResource" int the code, first of all set the default value in the layout.xml

why the last answer be deleted when i answer by chinease ? :(

ccc
  • 1
0

Try:

checkBox.setBackgroundColor(getContext().getResources().getColor(R.color.red));

If this doesn`t work then setBackgroundColor is broken for Xperia x10

Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
  • What about other setBackground (setBackgroundDrawable) methods? Does setBackgroundColor works for other Views? – Dmytro Danylyk Feb 04 '12 at 10:38
  • If I am trying to add image resource as a background by code that is also not working in xperia as working on other devices. – Saurabh Pareek Feb 04 '12 at 10:38
  • Then sorry I guess setBackgroundColor is broken for Xperia x10. Post ticket to official support or something like this, and close question.. – Dmytro Danylyk Feb 04 '12 at 10:41