새 구성 요소를 만들 필요가 없습니다.
먼저 낮은 API를 지원하려면 SwitchPreference 대신 CheckBoxPreference
을 사용해야합니다.
기존 android.support.v7.widget.SwitchCompat
위젯을 사용하여 l_switch.xml
과 같은 새 레이아웃 파일을 만듭니다. 다음 코드를 사용합니다
android:widgetLayout="@layout/l_switch"
이 강제로, 직접 CheckBoxPreference에, 당신의 SwitchPreference PreferenceFragment
에서CheckBoxPreference에, 그리고
yourSwitch = findPreference("key_for_this_component");
yourSwitch.setWidgetLayoutResource(R.layout.l_switch);
을
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.SwitchCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/checkbox" <!-- IMPORTANT -->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false" <!-- IMPORTANT -->
android:focusable="false" <!-- IMPORTANT -->
android:gravity="center" />
를하거나 CheckBoxPreference는 SwitchCompat
스타일을 사용합니다.
나는 나의 대답을 편집했다. 수정 된 답변을 사용하십시오. – jyoon