As the title says, I got a problem with Checkbox
Background
on Xperia phones. The code is working fine on every devices but Xperia ones. It simply shows no background.
myCheckbox.setBackgroundResource(R.drawable.customBackground);
Neither does myCheckbox.setBackgroundColor(Color.RED);
As stated in this other post on SO, Background
methods seem broken on Xperia. I tried the given fix, and it works well for colors.
myCheckbox.setDrawingCacheEnabled(true);
myCheckbox.setDrawingCacheBackgroundColor(Color.RED);
Problem is there is no setDrawingCacheBackgroundResource(int)
method for me.
Hence there are my two questions :
1- Does someone know how to fix it ?
2- If someone knows, how can I know if the phone actually is a Xperia ? Just to do something like
if( /*phone is Xperia*/ )
/*Use fix*/
else
/*Proceed normaly*/
Thanks guys !
I tried this but I find it not satisfying :
myCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton checkbox, boolean checked)
{
layout_checkboxsubstitute.setBackgroundResource(checked ? R.drawable.customBackgroundStateOn : R.drawable.customBackgroundStateOff);
}
});
I created a Layout
and show it instead of Checkbox
itself. I have to change Background
manually. I'd rather stay with myCheckbox.setBackgroundResource(R.drawable.customBackground);
which is way simplier.
Does someone have a better solution ?