SwitchPreferencepublic class SwitchPreference extends TwoStatePreference A {@link Preference} that provides a two-state toggleable option.
This preference will store a boolean into the SharedPreferences. |
Fields Summary |
---|
private final Listener | mListener | private CharSequence | mSwitchOn | private CharSequence | mSwitchOff |
Constructors Summary |
---|
public SwitchPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)Construct a new SwitchPreference with the given style options.
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.SwitchPreference, defStyleAttr, defStyleRes);
setSummaryOn(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOn));
setSummaryOff(a.getString(com.android.internal.R.styleable.SwitchPreference_summaryOff));
setSwitchTextOn(a.getString(
com.android.internal.R.styleable.SwitchPreference_switchTextOn));
setSwitchTextOff(a.getString(
com.android.internal.R.styleable.SwitchPreference_switchTextOff));
setDisableDependentsState(a.getBoolean(
com.android.internal.R.styleable.SwitchPreference_disableDependentsState, false));
a.recycle();
| public SwitchPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)Construct a new SwitchPreference with the given style options.
this(context, attrs, defStyleAttr, 0);
| public SwitchPreference(android.content.Context context, android.util.AttributeSet attrs)Construct a new SwitchPreference with the given style options.
this(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
| public SwitchPreference(android.content.Context context)Construct a new SwitchPreference with default style options.
this(context, null);
|
Methods Summary |
---|
public java.lang.CharSequence | getSwitchTextOff()
return mSwitchOff;
| public java.lang.CharSequence | getSwitchTextOn()
return mSwitchOn;
| protected void | onBindView(android.view.View view)
super.onBindView(view);
View checkableView = view.findViewById(com.android.internal.R.id.switchWidget);
if (checkableView != null && checkableView instanceof Checkable) {
if (checkableView instanceof Switch) {
final Switch switchView = (Switch) checkableView;
switchView.setOnCheckedChangeListener(null);
}
((Checkable) checkableView).setChecked(mChecked);
if (checkableView instanceof Switch) {
final Switch switchView = (Switch) checkableView;
switchView.setTextOn(mSwitchOn);
switchView.setTextOff(mSwitchOff);
switchView.setOnCheckedChangeListener(mListener);
}
}
syncSummaryView(view);
| public void | setSwitchTextOff(java.lang.CharSequence offText)Set the text displayed on the switch widget in the off state.
This should be a very short string; one word if possible.
mSwitchOff = offText;
notifyChanged();
| public void | setSwitchTextOff(int resId)Set the text displayed on the switch widget in the off state.
This should be a very short string; one word if possible.
setSwitchTextOff(getContext().getString(resId));
| public void | setSwitchTextOn(java.lang.CharSequence onText)Set the text displayed on the switch widget in the on state.
This should be a very short string; one word if possible.
mSwitchOn = onText;
notifyChanged();
| public void | setSwitchTextOn(int resId)Set the text displayed on the switch widget in the on state.
This should be a very short string; one word if possible.
setSwitchTextOn(getContext().getString(resId));
|
|