简体   繁体   English

AndroidX首选项库DropDownPreferences在API <24上不起作用

[英]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.setDefaultNightModegetActivity().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.

相关问题 我无法安装 androidx.preference 库 - i can't install androidx.preference library Vector Drawables标志在支持库24+上不起作用 - Vector Drawables flag doesn't work on Support Library 24+ OnOptionsItemSelected不适用于Android API 19(但适用于android 24) - OnOptionsItemSelected doesn't work on android API 19 (but works on android 24) selectedItemId 在 androidx.navigation:navigation 库更新后不再工作 - selectedItemId doesn't work anymore after androidx.navigation:navigation library update Androidx 导航视图 - `setNavigationItemSelectedListener` 不起作用 - Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work 在 Android 7 上实现 androidx 生物识别库后,字体缩放不起作用 - Font scaling doesn't work after implementing androidx biometric library on Android 7 无法在布局文件中检测到Androidx首选项库 - Unable to detect Androidx Preference library in layout file AndroidX 首选项库标题和摘要文本大小 - AndroidX Preference library title and summary text sizes 如何在新的 AndroidX 库中自定义首选项屏幕 - How to customize Preference Screen in new AndroidX Library setOnPreferenceClickListener函数不适用于Android上的Preference - setOnPreferenceClickListener function doesn't work for Preference on Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM