I've finished migrating to AndroidX Preference library and while everything works perfect on API 24-29, it reacts weirdly on older ones<24. The Dropdown preferences are not responding on selection but the dialog ones are. What changed on API 24 that might cause this? I should mention that the official Github sample app works as intended even on API 16!
UPDATE - I've managed to find a temporary workaround, by changing DropDownPreference
s to ListPreference
. However, it didn't fix it yet. But after applying another theme (as in the clip below - between Light\Dark) the value of the ListPreference changed and work properly! (The theme changing is done by AppCompatDelegate.setDefaultNightMode
and getActivity().recreate()
)
AVD API 29 (also 24-28) - Everything works:
AVD API 21 (also 22-23) - Nothing happens when choosing other options
(While we're at it - any way to decrease the size of the emulator video capture?)
Here is my preferences.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="general_settings"
android:title="@string/settings_title_general">
<ListPreference
android:defaultValue="system"
android:entries="@array/locale"
android:entryValues="@array/localeValues"
android:key="locale_override"
android:summary="@string/settings_locale_summary"
android:title="@string/settings_locale_title"
app:useSimpleSummaryProvider="true" />
<DropDownPreference
android:defaultValue="@string/settings_units_option_default"
android:entries="@array/unitOfMeasure"
android:entryValues="@array/unitOfMeasureValues"
android:key="unit_of_measure"
android:summary="@string/settings_uom_summary"
android:title="@string/settings_uom_title"
app:useSimpleSummaryProvider="true" />
<DropDownPreference
android:defaultValue="@string/settings_theme_option_default"
android:entries="@array/theme"
android:entryValues="@array/themeValues"
android:key="theme"
android:summary="@string/settings_theme_summary"
android:title="@string/settings_theme_title"
app:useSimpleSummaryProvider="true" />
<DropDownPreference
android:defaultValue="Internal"
android:entries="@array/storage"
android:entryValues="@array/storageValues"
android:key="storage_location"
android:summary="@string/settings_storage_summary"
android:title="@string/settings_storage_title"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory
android:key="about"
android:title="@string/settings_title_about">
<Preference
android:key="version"
android:title="@string/settings_version_title"
app:enableCopying="true"
app:selectable="false" />
<Preference
android:key="privacy_policy"
android:summary="Read the privacy policy that Google made us put up..."
android:title="Privacy Policy">
<intent
android:action="android.intent.action.VIEW"
android:data="https://sites.google.com/site/skydivinglogbook/privacy-policy" />
</Preference>
and the SettingFragment:
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
settingsRepository = new SettingsRepository(mContext);
LocaleHelper.updateResources(mContext);
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
//version name
findPreference(Constants.PREF_KEY_VERSION).setSummary(BuildConfig.VERSION_NAME);
}
</PreferenceCategory>
</PreferenceScreen>