Я создал PreferenceScreen следующим образом:Missing переключатель для SwitchPreferenceCompat
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceCategory
android:title="@string/title_telephone">
<android.support.v7.preference.SwitchPreferenceCompat
android:key="checkbox_preference_telephone_recording"
android:title="@string/checkbox_telephone_recording"
android:defaultValue="@string/default_checkbox_telephone_recording"/>
<android.support.v7.preference.SwitchPreferenceCompat
android:key="checkbox_preference_telephone_accel"
android:title="@string/checkbox_telephone_accel"
android:defaultValue="@string/default_checkbox_telephone_accel"/>
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>
Однако, по некоторым причинам я не могу найти, не отображаются переключатели. У меня нет ошибок. Вот как это выглядит:
кодекса
public class SettingsFragment extends PreferenceFragmentCompat {
private Preference mListPreference;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
}
}
styles.xml
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="MyActionBarTheme" parent="android:Widget.Material.Light.ActionBar">
<item name="android:background">@color/colorAccent</item>
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Material.Widget.ActionBar.Title">
<item name="android:textColor">@color/colorPrimary</item>
</style>
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">@color/background_material_light</item>
<item name="android:colorPrimary">@color/primary_material_light</item>
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
<item name="preferenceStyle">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
</resources>
Атрибут DefaultValue должен принять логическое значение не строка – NezSpencer
Это делает не важно. Предоставляемые ресурсы являются логическими значениями – PKlumpp
вы можете разместить код для вашего PreferenceFragment – NezSpencer