安卓设置自定义偏好分隔线颜色

4

我正在制作一个使用偏好设置的应用程序,用于设置菜单。我已经有了菜单中不同对象的代码,但分隔线是淡白色的。我想将其变成较深的颜色(如黑色),以便更容易看到。我的当前代码如下:

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);

你找到解决方案了吗? - DuosDuo
1个回答

5
只需将以下内容添加到您的PreferenceStyle中,并删除listSeparatorTextViewStyle
<item name="android:listDivider">@color/text_color_dark</item>
<item name="android:dividerHeight">1dp</item>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接