如何更改支持包的首选项对话框颜色?

How to change support package's preferences dialog colors?

我能够在没有支持包的情况下自定义首选项的对话框主题。由于我切换到支持包(我的首选项片段现在扩展 PreferenceFragmentCompat 而不是 PreferencesFragment),我无法更改颜色。

到目前为止,我已将此添加到我的主题中:

<item name="preferenceTheme">
    @style/MyPreferenceTheme
</item>
<item name="android:dialogTheme">@style/DialogStyle</item>
<item name="android:alertDialogTheme">@style/DialogStyle</item>
<item name="android:dialogPreferenceStyle">@style/DialogStyle</item>

// ...

<style name="MyPreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
<!--<style name="MyPreferenceTheme">-->
    <item name="colorAccent">@android:color/white</item>
    <item name="android:background">@color/bg0</item>
    <item name="android:textColor">@color/fg0</item>

    <item name="android:windowBackground">@color/bg0</item>
    <item name="android:windowTitleStyle">@style/WindowTitleStyle</item>

    <item name="android:keyTextColor">@color/fg0</item>
    <item name="android:textColorAlertDialogListItem">@color/fg0</item>
    <item name="android:textColorPrimary">@color/fg0</item>
    <item name="android:textColorSecondary">@color/fg0</item>
    <item name="android:textColorTertiary">@color/fg0</item>

    <item name="colorControlNormal">@color/fg0</item>
    <item name="colorControlActivated">@color/fg0</item>
    <item name="colorControlHighlight">@color/fg0</item>
</style>


<style name="DialogStyle" parent="Theme.AppCompat.Dialog">
    <item name="colorAccent">@android:color/white</item>
    <item name="android:background">@color/bg0</item>
    <item name="android:textColor">@color/fg0</item>

    <item name="android:windowTitleStyle">@style/WindowTitleStyle</item>
    <item name="android:windowBackground">@color/bg0</item>

    <item name="android:keyTextColor">@color/fg0</item>
    <item name="android:textColorAlertDialogListItem">@color/fg0</item>
    <item name="android:textColorPrimary">@color/fg0</item>
    <item name="android:textColorSecondary">@color/fg0</item>
    <item name="android:textColorTertiary">@color/fg0</item>

    <item name="colorControlNormal">@color/fg0</item>
    <item name="colorControlActivated">@color/fg0</item>
    <item name="colorControlHighlight">@color/fg0</item>
</style>

<style name="WindowTitleStyle" parent="TextAppearance.AppCompat.Title">
    <item name="android:textColor">@color/fg0</item>
</style>

我只想要黑色背景和白色文本/小部件。 fg0 是白色的,bg0 是黑色的。但是对话框显示的是白色背景和黑色文本。标题是不可见的(我假设它是白色的,这是正确的)。

在绝望的情况下,我还尝试只为对话框使用自定义布局,setDialogLayoutResource - 我想复制资源 Android 用于对话框并更改颜色.但我不知道 Android 资源在哪里。在首选项的源代码中,除了我发现的 https://android.googlesource.com/platform/frameworks/support/+/master/v7/appcompat/res/layout/ and https://android.googlesource.com/platform/frameworks/support/+/master/v7/preference/res/layout/ 之外,没有对布局文件的明确引用,但我怎么知道它是哪个?

如何调整主题?这个简单的任务不可能这么复杂!

另外请解释从 "I want to set the background color of the preferences dialog to black" 到我必须在 XML 中设置的确切属性的确切路径。在哪里找到:1.这是哪个对话框,2.它有什么属性3.设置这些属性有什么作用。 (最好不必深入挖掘源代码)。

文档告诉我们查看源代码,例如在 R.attr 中,但除了搜索包含 "dialog" 或 "preferences" 的名称外,我不知道该怎么做。 None 到目前为止我尝试过的属性有所帮助。

相关:没有人使用(或重新设计)PreferenceFragmentCompat?很难找到有关此的信息,而且似乎也没有人知道。你用什么代替? (这些问题仅供评论)

我发现了问题:

我正在使用

<item name="android:alertDialogTheme">@style/DialogStyle</item>

应该是

<item name="alertDialogTheme">@style/DialogStyle</item>

非常令人恼火,特别是 Android Studio 没有捕获这些错误甚至自动完成 android:alertDialogTheme