在preferences.xml上设置背景颜色

时间:2014-09-29 12:27:34

标签: java android background

我正在尝试更改preferences.xml上的背景颜色。默认颜色为白色。有没有办法改变它?它也将应用于preferences.xml子屏幕。

在这里,我使用自定义“drawable”来设置背景颜色。可绘制文件名为bg_gradient.xml。这是我的代码:

RES /抽拉/ bg_gradient.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="270"
        android:gradientRadius="750"
        android:endColor="@color/bg_gradient_end"
        android:startColor="@color/bg_gradient_start"
        android:type="linear" />
</shape>

提前致谢。

1 个答案:

答案 0 :(得分:1)

在styles.xml中添加该代码

<style name="PreferencesTheme">
<item name="android:windowBackground">@drawable/background_image</item>
<item name="android:background">#A4A4A4</item>
</style>

并在manifest中为SettingsActivity类设置主题。像这样:

 android:theme="@style/PreferencesTheme"

根据你改变背景颜色。