Ang*_*274 4 android 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>
Run Code Online (Sandbox Code Playgroud)
样式.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>
Run Code Online (Sandbox Code Playgroud)
最后:
setTheme(R.style.PreferenceStyle);
Run Code Online (Sandbox Code Playgroud)
只需将以下内容添加到您的PreferenceStyle并删除 listSeparatorTextViewStyle
<item name="android:listDivider">@color/text_color_dark</item>
<item name="android:dividerHeight">1dp</item>
Run Code Online (Sandbox Code Playgroud)