我能夠在沒有支持包的情況下自定義首選項的對話框主題。由於我切換到支持包(我的偏好片段現在延伸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是黑色。但對話框顯示白色的bg和黑色文本。標題是不可見的(我認爲它是白色的,這是正確的)。
在絕望的行爲中,我也嘗試過使用對話框的自定義佈局,setDialogLayoutResource
- 我想複製Android用於對話框的資源並更改顏色。但我不知道Android資源的位置。在首選項的源代碼中,沒有明確提及佈局文件,除此之外我發現了https://android.googlesource.com/platform/frameworks/support/+/master/v7/appcompat/res/layout/和https://android.googlesource.com/platform/frameworks/support/+/master/v7/preference/res/layout/,但我怎麼知道它是哪一個?
如何調整主題?這個簡單的任務不能這麼複雜!
也請解釋什麼路徑是從「我想設置偏好對話框的背景顏色爲黑色」到我必須在XML中設置的確切屬性。我在哪裏可以找到:1.哪個對話框是這樣的,2.它具有哪些屬性3.設置這些屬性的效果是什麼。 (最好不需要挖掘源代碼)。
文檔告訴我們看源代碼,在R.attr但除了搜索名稱包含「對話框」或「偏好」我不知道該怎麼做。我迄今嘗試過的所有屬性都沒有幫助。
相關:沒有人使用(或恢復)PreferenceFragmentCompat
?難以找到關於這方面的信息,而且似乎也沒有人知道。你用什麼來代替? (這些問題僅限於評論)。