如何在新的AndroidX库中自定义首选项屏幕

如何在新的AndroidX库中自定义首选项屏幕,android,Android,我刚刚从支持库迁移到AndroidX。我的大部分代码都可以正常工作,但突然我的自定义首选项主题停止工作 我的应用程序大部分是深色背景,所以我将文本颜色设置为白色变体,但在我的设置中,背景颜色是浅的,所以首选项的标题和副标题应该是深色变体。在我尝试自定义我的首选项片段时,我使用了此->中的解决方案,遗憾的是,从支持库迁移到AndroidX后,此解决方案停止工作 以下是迁移后我的实际依赖项: implementation 'androidx.appcompat:appcompat:1.1.0-alp

我刚刚从支持库迁移到AndroidX。我的大部分代码都可以正常工作,但突然我的自定义首选项主题停止工作

我的应用程序大部分是深色背景,所以我将文本颜色设置为白色变体,但在我的设置中,背景颜色是浅的,所以首选项的标题和副标题应该是深色变体。在我尝试自定义我的首选项片段时,我使用了此->中的解决方案,遗憾的是,从支持库迁移到AndroidX后,此解决方案停止工作

以下是迁移后我的实际依赖项:

implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
这是我过去工作的实际主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- General theme colors -->
    <item name="colorPrimary">@color/appColorPrimary</item>
    <item name="colorPrimaryDark">@color/appColorPrimaryDark</item>
    <item name="colorAccent">@color/appColorAccent</item>

    <!-- Text Appearance styles -->
    <item name="android:textViewStyle">@style/TextViewStyle.Serif</item>
    <item name="android:textColorPrimary">@color/textColorPrimary</item>
    <item name="android:textColorSecondary">@color/textColorSecondary</item>
    <item name="android:textColorTertiary">@color/textColorTertiary</item>
    <item name="android:textColorLinkInverse">@color/textColorLinkInverse</item>

<!--For the SearchView cursor color-->
    <item name="colorControlActivated">@color/white</item>

<!--Custom styles and themes -->
    <item name="preferenceTheme">@style/AppTheme.PreferenceTheme</item>
    <item name="actionOverflowMenuStyle">@style/AppTheme.OverflowMenu</item>
    <item name="alertDialogTheme">@style/AlertDialogStyle</item>
    <!-- Custom attributes defined in attrs.xml -->
    <item name="dividerColor">@color/dividerColor</item>
</style>


<!--Preference screen theme-->
<style name="AppTheme.PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
    <!--Overriding textColor primary/secondary from main theme-->
    <item name="android:textColorPrimary">@color/textColorPrimaryInverse</item>
    <item name="android:textColorSecondary">@color/textColorSecondaryInverse</item>
    <item name="android:colorControlActivated">@color/appColorPrimary</item>
</style>

@颜色/appColorPrimary
@颜色/appColorPrimaryDark
@颜色/appColorAccent
@style/TextViewStyle.Serif
@颜色/文本颜色主
@颜色/文本颜色辅助
@颜色/文本颜色
@颜色/文本颜色链接反转
@颜色/白色
@style/AppTheme.PreferenceTheme
@style/AppTheme.OverflowMenu
@样式/警报对话框样式
@颜色/分割颜色
@颜色/文本颜色主反转
@颜色/文本颜色二次反转
@颜色/appColorPrimary

对于这种新情况有什么解决方案吗?

您的首选主题的
parent
现在应该是
PreferenceThemeOverlay
,我尝试了这个解决方案,但它仍然使用主主题颜色,而不是自定义AppTheme中提供的颜色。PreferenceTheme:\您的preference.xml是否引用了旧版本中的任何内容,如
?迁移AndroidX后,我更改了preference.xml的标记,如下所示:
。我完全像你一样实现了我的自定义偏好主题,而且效果很好。不,在迁移过程中,它没有改变,仍然是这样:关于这个主题有什么新闻吗?我也有同样的问题。我的应用程序几乎是黑色的,黑色背景上的黑色首选标题不太好用。唯一适合我的解决方案是使用我的自定义文本颜色样式覆盖所有可用的首选项布局。覆盖textColorPrimary和textColorSecondary的解决方案在迁移到androidx.preference后停止工作