diff --git a/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml b/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml index 52779bcabf000..85c01c5732cab 100644 --- a/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml +++ b/packages/SettingsLib/MainSwitchPreference/res/layout/main_switch_bar.xml @@ -19,6 +19,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="match_parent" + android:background="?android:attr/colorBackground" android:orientation="vertical"> mSwitchChangeListeners = new ArrayList<>(); private MainSwitchBar mMainSwitchBar; - private String mTitle; + private CharSequence mTitle; private RestrictedLockUtils.EnforcedAdmin mEnforcedAdmin; @@ -81,24 +80,28 @@ public class MainSwitchPreference extends TwoStatePreference { setLayoutResource(R.layout.main_switch_layout); if (attrs != null) { - TypedArray a = context.obtainStyledAttributes(attrs, + final TypedArray a = context.obtainStyledAttributes(attrs, androidx.preference.R.styleable.Preference, 0 /*defStyleAttr*/, 0 /*defStyleRes*/); final CharSequence title = TypedArrayUtils.getText(a, androidx.preference.R.styleable.Preference_title, androidx.preference.R.styleable.Preference_android_title); - if (!TextUtils.isEmpty(title)) { - setTitle(title.toString()); - } + setTitle(title); a.recycle(); } } - /** - * Set the preference title text - */ - public void setTitle(String text) { - mTitle = text; + @Override + public void setChecked(boolean checked) { + super.setChecked(checked); + if (mMainSwitchBar != null) { + mMainSwitchBar.setChecked(checked); + } + } + + @Override + public void setTitle(CharSequence title) { + mTitle = title; if (mMainSwitchBar != null) { mMainSwitchBar.setTitle(mTitle); }