2016-05-18 66 views
0

我使用AppCompatPreferenceActivity,它使用PreferenceActivity簡化的用戶界面(沒有片段),但帶有PreferenceFragment的雙窗格用戶界面。Android PreferenceFragment標題文字顏色

到現在爲止,我只用一個光主題(主題我的父母是Theme.AppCompat.Light)並沒有什麼問題,它看起來像這樣當兩個窗格模式:

enter image description here

我m現在實現了一個黑暗的主題,所以這一次,我的主題的父母是「Theme.AppCompat」。

它看起來是這樣的:

enter image description here

正如你所看到的,偏好片段的標題是黑色的暗灰色背景。我怎樣才能設置這個「標題」顏色?

注:預棒棒糖,很容易,我們只需要ATT,要優先活動主題:

<item name="android:textColorSecondary">#AAAAAA</item> 

...但它不會對棒棒糖和棉花糖工作了。

有什麼想法?

回答

0

通過檢查PreferenceActivity代碼,我最終發現,在右窗格中的標題是不是偏好片段的一部分,但片段「breadcrumb」。

通過使用這個關鍵字(「breadcrumb」)搜索答案,我看到有人已經問過同樣的事情,而且接受的答案很棒,詳細介紹瞭如何做到這一點,以及爲什麼它更復雜一些而不僅僅是改變一種風格的顏色。

這裏的問題:Changing the highlight and title color for fragments in PreferenceActivity

和直接鏈接到了答案:https://stackoverflow.com/a/27078485/1534408

0

我改變它通過覆蓋類別主題。

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    //other stuff 
    <item name="preferenceTheme">@style/MyPrefTheme</item> 
</style> 

<style name="MyPrefTheme" parent="@style/PreferenceThemeOverlay"> 
    <item name="preferenceCategoryStyle">@style/CategoryStyle</item> 
    <item name="android:preferenceCategoryStyle">@style/CategoryStyle</item> 
</style> 

<style name="CategoryStyle" parent="Preference.Category"> 
    <item name="android:layout">@layout/category_view</item> 
</style> 

佈局/ category_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView android:id="@android:id/title" 
      style="?android:attr/listSeparatorTextViewStyle" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:textColor="@color/white" 
      android:layout_height="wrap_content" 
    /> 

瞭解詳情,請訪問Preference style.xml

happyCoding;

+0

謝謝。編譯時出現以下消息:「無法解析符號'Preference.Category'」。 –

+0

請確保您使用的是最新版本的v7 lib – Bharatesh

+0

我沒有使用支持偏好類,而是使用了「正常」類,而我在-v21樣式文件中,因爲我所描述的問題僅適用於API 21,優越。在API 21之前沒有問題。 –

0

你試過這樣嗎?

在styles.xml

<style name="PreferenceScreen" parent="YourApplicationThemeOrNone"> 
    <item name="android:textColor">@color/TitleColor</item> 
</style> 

在清單

<activity 
     android:name="MyPreferenceActivity" 
     ... 
     android:theme="@style/PreferenceScreen" > 
</activity> 
+0

謝謝,但這不起作用。 –