问题
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.
回答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);
回答2:
Try:
checkBox.setBackgroundColor(getContext().getResources().getColor(R.color.red));
If this doesn`t work then setBackgroundColor is broken for Xperia x10
回答3:
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 ? :(
来源:https://stackoverflow.com/questions/9139747/checkbox-background-issue-in-android-xperia-x10