简体   繁体   中英

Set the background color on preferences.xml

I'm trying to change the background color on preferences.xml . The default color is white. Is there a way to change it? It also will be applied to the preferences.xml subscreens.

Here, I'm using custom "drawable" to set the background color. The drawable file name is bg_gradient.xml . Here is my code:

res/drawable/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>

Thanks in advance.

Add that code in styles.xml

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

and set theme for SettingsActivity class in manifest . like this :

 android:theme="@style/PreferencesTheme"

change background color according to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM