PreferenceFragment를 사용하여 단일 SwitchPreference가있는 xml 파일을 팽창 시켰습니다. 아래의 이미지와 일치하도록 SwitchPreference의 제목을 포함하여 해당 환경 설정의 배경색을 어떻게 만들 수 있습니까? 배경 설정을 시도했지만 스위치 아이콘의 배경색 만 설정할 수 있습니다.Android SwitchPreference에 배경색을 추가하려면 어떻게해야하나요?
1
A
답변
0
나는 레이아웃에 Style.xml
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<item name="colorControlActivated">@color/yourcolor</item>
</style>
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="false"
android:gravity="center"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
app:switchMinWidth="@dimen/switch_size"
app:theme="@style/SwitchTheme" />
0
styles.xml을 스타일
를 사용하여 이런 짓을했는지 (style.xml에서이 스타일을 값 폴더에있는 파일)
<resources>
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<!-- switch on thumb & track color -->
<item name="colorControlActivated">#02c754</item>
<!-- switch off thumb color -->
<item name="colorSwitchThumbNormal">#f1f1f1</item>
<!-- switch off track color -->
<item name="android:colorForeground">#42221f1f</item>
</style>
</resources>
your_layout_activity.xml는
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="true"
android:gravity="center"
android:paddingLeft="30dp"
android:theme="@style/SwitchTheme"
app:switchMinWidth="55dp"/>
이 소스는 나를 위해 일한다. 이걸로 해보 려구요.
https://stackoverflow.com/questions/21235829/custom-switchpreference-in-android/21854548 –
텍스트 뒤의 색상을 포함한 전체 배경을 변경하려고합니다. –