سؤال

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 !

هل كانت مفيدة؟

المحلول 2

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 ?

نصائح أخرى

There is some issue with xperia for setBackgroundColor(). but it works with setDrawingCacheBackgroundColor();

CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox1);
checkBox.setDrawingCacheEnabled(true);
checkBox.setDrawingCacheBackgroundColor(Color.RED);

In case if you want to get phone manufacturer and model you can get it using,

String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top