Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

android - change background color of Preference

I have a PreferenceCategory, xml file and I have defined all preferences in it, I call this from class that extends PreferenceActivity. I am unable to set the background of my settings screen, this screen is displayed with help of xml file shown below. Please see that I have already defined the android:background="#041A37", still the screen remains default color: black.

public class MyPreferenceActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Context mContext=super.getBaseContext();
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.preference);
        //v.setBackgroundColor(Color.rgb(4, 26, 55));
    }
}

preference.xml is

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#041A37" >

    <PreferenceCategory>
        <com.dropcall.SeekBarPreference
            android:background="#041A37"
            android:defaultValue="5"
            android:key="@string/Interference_Delay"
            android:progressDrawable="@drawable/seekbardrawable"
            android:title="Seconds Delay until intereference" />

        <com.dropcall.SeekBarPreference2
            android:defaultValue="30"
            android:key="@string/Drop_Delay"
            android:progressDrawable="@drawable/seekbardrawable"
            android:title="Seconds delay until drop" />

        <CheckBoxPreference
            android:background="@drawable/state_normal"
            android:defaultValue="true"
            android:key="@string/Drop_Option"
            android:title="Close after call drop" />
        <CheckBoxPreference
            android:background="@drawable/state_normal"
            android:defaultValue="true"
            android:key="@string/Timer_Option"
            android:title="Start timers on launch" />
    </PreferenceCategory>

</PreferenceScreen>

Although I have set android:background="#041A37" in every file, the background doesn't turn into navy blue, or any other color for that matter. It remains default color, black. How to change the background color. Please let me know any pointers / hints , if you had faced same issue let me know what changes you made to set the background color.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can define a theme and then set this for your PreferenceActivity in the manifest. Your theme can then define a a background color or a windowBackground image should you prefer that.

Manifest:

    <activity android:label="@string/app_label" android:name=".client.PreferencesActivity"
        android:theme="@style/PreferencesTheme">
        <intent-filter>                                
        </intent-filter>
    </activity>

Then add the theme to your styles.xml

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

In the above snippet there's both a background color and a background image defined to show how to do it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...