Change/Customize 首选项屏幕警报对话框

Change/Customize Preference Screen Alert Dialog

我用 androidx 首选项库创建了一个首选项屏幕。问题是当我单击 EditTextPreference 时,警告对话框完全是白色的。我想这是因为我在我的应用程序主题中定义了主要文本颜色和次要文本颜色。那么如何为首选项警报对话框应用自定义主题呢?这是当我点击 EditTextPreference 时对话框现在的样子:

Style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/layoutBG</item>
    <item name="backgroundColor">@color/layoutMainBG</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">@color/textPrimaryLight</item>
    <item name="android:textColorSecondary">@color/textSecondaryLight</item>
</style>

colors.xml

<resources>
    <color name="colorPrimary">#6200EE</color>
    <color name="colorPrimaryDark">#3700B3</color>
    <color name="colorAccent">@color/textBlue</color>
    <color name="textPrimaryLight">#ffffff</color>
    <color name="textSecondaryLight">#D7D7D7</color>
    <color name="charging">#388e3c</color>
    <color name="textBlue">#70b3c6</color>
    <color name="layoutBG">#171717</color>
    <color name="layoutMainBG">#0d0d0d</color>
</resources>

我通过在我的 AppTheme 中添加这两行来修复它

        <item name="colorBackgroundFloating">@color/layoutBG</item>
        <item name="android:editTextColor">@color/textPrimaryLight</item>

所以我的新 AppTheme 看起来像这样

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorAccent</item>
        <item name="colorPrimaryDark">@color/layoutBG</item>
        <item name="backgroundColor">@color/layoutMainBG</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@color/textPrimaryLight</item>
        <item name="android:textColorSecondary">@color/textSecondaryLight</item>
        <item name="colorBackgroundFloating">@color/layoutBG</item>
        <item name="android:editTextColor">@color/textPrimaryLight</item>
    </style>