[英]AndroidX Preference library DropDownPreferences doesn't work on API < 24
I've finished migrating to AndroidX Preference library and while everything works perfect on API 24-29, it reacts weirdly on older ones<24. 我已经完成了向AndroidX首选项库的迁移,尽管一切在API 24-29上都可以完美运行,但对于<24岁的老版本,它的反应却很怪异。 The Dropdown preferences are not responding on selection but the dialog ones are.
下拉首选项在选择时不响应,而对话框则响应。 What changed on API 24 that might cause this?
API 24发生了什么变化可能会导致这种情况? I should mention that the official Github sample app works as intended even on API 16!
我应该提到的是,即使在API 16上,官方Github示例应用程序仍可以正常工作!
UPDATE - I've managed to find a temporary workaround, by changing DropDownPreference
s to ListPreference
. 更新 -通过将
DropDownPreference
更改为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!
但是在应用了另一个主题之后(如下面的片段中的Light \\ Dark之间),ListPreference的值已更改并且可以正常工作! (The theme changing is done by
AppCompatDelegate.setDefaultNightMode
and getActivity().recreate()
) (主题更改由
AppCompatDelegate.setDefaultNightMode
和getActivity().recreate()
)
AVD API 29 (also 24-28) - Everything works: AVD API 29(也是24-28)-一切正常:
AVD API 21 (also 22-23) - Nothing happens when choosing other options AVD API 21(也是22-23)-选择其他选项时没有任何反应
(While we're at it - any way to decrease the size of the emulator video capture?) (我们正在这样做-是否可以减小模拟器视频捕获的大小?)
Here is my preferences.xml: 这是我的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: 和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>
You're not using any androidx.preference.*
in the XML, alike: 您没有在XML中使用任何
androidx.preference.*
,类似:
androidx.preference.PreferenceScreen
androidx.preference.PreferenceCategory
androidx.preference.Preference
androidx.preference.ListPreference
androidx.preference.DropDownPreference
so you probably cannot refer to AndroidX. 因此您可能无法参考AndroidX。
That useSimpleSummaryProvider
is useless, when not being used with androidx.preference
>= 1.1.0
. 当不与
androidx.preference
> = 1.1.0
一起使用时, useSimpleSummaryProvider
是无用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.