PreferenceFragment で SwitchPreference 要素のスタイルを設定しようとしています。
私がしたことは、スタイルを定義することでした
<style name="CustomSwitchPreference">
<item name="android:thumb">@drawable/custom_switch</item>
<item name="android:background">@drawable/switch_background</item>
</style>
そして、スタイルを私の要素に設定します
<SwitchPreference
android:key="log_all_toast"
android:width="10dip"
android:height="7dip"
android:switchTextOn="@string/yes"
android:switchTextOff="@string/no"
android:title="@string/settings_log_all_toast_title"
android:summary="@string/settings_log_all_toast_summary"
style="@style/CustomSwitchPreference"/>
2 つのドローアブルは、適切に定義されたセレクターです。実際、stackoverflow の別の投稿からインスピレーションを得ました。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_disabled" />
<item android:state_pressed="true" android:drawable="@drawable/switch_pressed" />
<item android:state_checked="true" android:drawable="@drawable/switch_active" />
<item android:drawable="@drawable/switch_default" />
と
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/switch_bg_disabled_holo_dark" />
<item android:state_focused="true" android:drawable="@drawable/switch_bg_focused_holo_dark" />
<item android:drawable="@drawable/switch_bg_holo_dark" />
何が起こるかは... 何もありません。エラーはありませんが、スタイリングもありません。
独自の SwitchPreference をスタイルできたことはありますか? 私はオンラインでそれについて多くを見つけることができませんでした.
ありがとうございました