Существует обходной путь, который я не уверен, насколько он полон, оборачивая то представление, которое используется в CheckBoxPreference (может пропустить некоторые функции, но в общем случае это работает).
Обходной путь будет использовать CheckBoxPreference для pre-API-14 и SwitchPreference для API 14 и выше.
Вот код:
public class SwitchPreference extends CheckBoxPreference
{
android.preference.SwitchPreference _switchPreference =null;
public SwitchPreference(final Context context)
{
super(context);
if(VERSION.SDK_INT>=VERSION_CODES.ICE_CREAM_SANDWICH)
_switchPreference=new android.preference.SwitchPreference(context);
}
public SwitchPreference(final Context context,final AttributeSet attrs)
{
super(context,attrs);
if(VERSION.SDK_INT>=VERSION_CODES.ICE_CREAM_SANDWICH)
_switchPreference=new android.preference.SwitchPreference(context,attrs);
}
public SwitchPreference(final Context context,final AttributeSet attrs,final int defStyle)
{
super(context,attrs,defStyle);
if(VERSION.SDK_INT>=VERSION_CODES.ICE_CREAM_SANDWICH)
_switchPreference=new android.preference.SwitchPreference(context,attrs,defStyle);
}
@Override
protected View onCreateView(final ViewGroup parent)
{
final View view;
if(VERSION.SDK_INT>=VERSION_CODES.ICE_CREAM_SANDWICH)
{
view=_switchPreference.getView(null,parent);
// set as checked the view and the view's children, each in case it extend from Checkable
ViewUtil.setChecked(view,isChecked());
// set as non-clickable the view and the view's children
ViewUtil.setClickable(view,false);
}
else view=super.onCreateView(parent);
return view;
}