2016-02-05 62 views
0

我正在製作一個應用程序,使用首選項設置菜單。我有菜單中不同對象的代碼,但分隔符是淡白色。我想使它變成更深的顏色(如黑色),以便更容易看到。我當前的代碼如下:Android設置自定義偏好分隔線顏色

的preferences.xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <PreferenceCategory 
     android:title="Appearance" /> 

    <ListPreference 
     android:key="color_scheme" 
     android:title="Color Scheme" 
     android:summary="Change the color scheme of the app" 
     android:dialogTitle="Color Scheme" 
     android:entries="@array/colors" 
     android:entryValues="@array/colors" 
     android:defaultValue="Default (Blue Gray)" /> 

    <PreferenceCategory 
     android:title="Other" /> 

    <Preference 
     android:key="@string/preference_reset" 
     android:title="Reset Values" 
     android:summary="Reset all values to their default value" /> 
</PreferenceScreen> 

styles.xml:

<style name="PreferenceStyle"> 
    <item name="android:textColorPrimary">@color/text_color_dark</item> 
    <item name="android:textColorSecondary">@color/text_color_gray</item> 
    <item name="android:listSeparatorTextViewStyle">@style/ListSeperatorColor</item> 
</style> 

<style name="ListSeperatorColor" parent="android:Widget.TextView"> 
    <item name="android:background">@color/text_color_dark</item> 
</style> 

最後:

setTheme(R.style.PreferenceStyle); 

回答

1

只需添加以下到您的PreferenceStyle並刪除列表SeparatorTextViewStyle

<item name="android:listDivider">@color/text_color_dark</item> 
<item name="android:dividerHeight">1dp</item>