我有一个带有几个SwitchPreferences的PreferencesFragment。
在极少数平板电脑上。我看到当一个开关设置为关闭并且用户将它们更改为打开时发生的问题,然后向下滚动以将SwitchPreference移动到屏幕外。当用户向上滚动时,开关已恢复为关闭状态。
例如,在下图中。如果用户将“启用背景”设置为“开”,则向下滚动。然后备份。 “启用背景”将再次关闭。有没有人知道为什么会在偶尔的设备上发生这种情况。
这是特定SwitchPrefence
的xml<PreferenceCategory
android:title="General"
android:key="pref_general_settings">
<SwitchPreference
android:key="pref_enable_backdrops"
android:title="Enable Backdrops"
android:summaryOff="Backdrops are not shown in various views"
android:summaryOn="Backdrops are shown in various views"
android:defaultValue="false" />
<SwitchPreference
android:key="pref_include_trailers"
android:title="Include Trailers"
android:summaryOff="Trailers will not be included in search results, the homescreen, and actor bio screens"
android:summaryOn="Trailers will be included in search results, the homescreen, and actor bio screens"
android:defaultValue="false" />
</PreferenceCategory>
PreferencesFragment
public class MainSettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
try {
FileUtils fileUtils = new FileUtils();
ServerInfo serverInfo = fileUtils.LoadLastConnected(getActivity());
if (serverInfo != null) {
if (serverInfo.FriendlyName != null && !serverInfo.FriendlyName.isEmpty())
this.findPreference("pref_server_name").setTitle(serverInfo.FriendlyName);
else
this.findPreference("pref_server_name").setTitle(serverInfo.HostNameOrIpAddress);
}
} catch (Exception e) {
// Do Something
}
}
}