CheckBox background issue in Android + Xperia x10

跟風遠走 提交于 2019-12-25 14:10:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!