API 29已弃用PreferenceScreen

时间:2019-08-10 06:06:54

标签: android

我确实创建了首选项XML,然后看到 Context wrapper = new ContextThemeWrapper(context, R.style.PopupMenu); PopupMenu popup = new PopupMenu(wrapper, v); 已被API 29弃用。替代品是什么?

您可以在此处看到折旧消息:

enter image description here

2 个答案:

答案 0 :(得分:7)

基于Google Document的API级别29中已弃用该标签,并且Google建议您改用AndroidX Preference Library

您可以在此link

中查看AndroidX首选项指南。

如果from collections import defaultdict ary = [3,2,3,4,7,2,4,7] #you don't need a defaultdict, but I like to use them just in case, instead of a dictionary, as a general practice rank = defaultdict(int) for x in ary: #first, we get all the values of the array and put them in the dict rank[x] = 0 count = 0 for x in sorted(rank): #now we go from lowest to highest in the array, adding 1 to the dict-value rank[x] = count count += 1 ary = [rank[x] for x in ary] print(ary) 之后仍然存在问题,可以使用

Migrate to Androidx

代替

<androidx.preference.PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">

</androidx.preference.PreferenceScreen>

这不是必需的,但是您也可以将此实现添加到Gradle中。

<PreferenceScreen
    xmlns:app="http://schemas.android.com/apk/res-auto">


</PreferenceScreen>

答案 1 :(得分:0)

official doc中所述:

  

该类已在API级别29中弃用。
  使用AndroidX Preference Library在所有设备上保持一致的行为