Background from PreferenceActivity is not applied to sub-PreferenceScreen

I am testing my application on a Nexus One and i have some problems. My theme is Light and when an inner sub PreferenceScreen is displayed, the window background becomes black instead of keeping the PreferenceActivity's one.

<PreferenceScreen android:title="main preferences">
    <PreferenceScreen android:title="sub screen">

What is the problem?


Asked by: Miller190 | Posted: 24-01-2022

Answer 1

Use this:

Create theme in style.xml file

<style name="Theme.SettingsBackground" parent="@android:style/Theme.NoTitleBar">
<item name="android:windowBackground">@android:color/black</item>

and then in manifest file use:

<activity android:name=".Settings" android:theme="@style/Theme.SettingsBackground"></activity>

Do this for all sub activities which you want.

Answered by: Elian369 | Posted: 25-02-2022

Answer 2

To best understand what is happening here you can refer to this piece of code from the source code for the PreferenceScreen class:

    protected void onClick() {
        if (getIntent() != null || getPreferenceCount() == 0) {


    private void showDialog(Bundle state) {
        Context context = getContext();
        ListView listView = new ListView(context);

        // Set the title bar if title is available, else no title bar
        final CharSequence title = getTitle();
        Dialog dialog = mDialog = new Dialog(context, TextUtils.isEmpty(title)
        if (!TextUtils.isEmpty(title)) {
        if (state != null) {

        // Add the screen to the list of preferences screens opened as dialogs

The way that I work around it is to set the parent background color by overriding onCreateView in the first preference added to the preference screen. Of course this requires some custom code but it's not terribly complicated, for instance to set a white background:

package com.justinbuser.livewallpapers;

import android.preference.PreferenceCategory;

public class VideoChooserPreferenceCategory extends PreferenceCategory{

    public VideoChooserPreferenceCategory(Context context) {

    protected View onCreateView(ViewGroup parent)
        return super.onCreateView(parent);

You would then of course need to use that custom category by altering your xml, i.e.:

<PreferenceScreen android:title="main preferences">
    <PreferenceScreen android:title="sub screen">
    <com.justinbuser.livewallpapers.VideoChooserPreferenceCategory android:title="sub screen category" />

Also, if you notice the android PreferenceScreen changes the theme based on whether or not a title is set, i.e. if a title exists it enables a theme that includes the title bar. So if you want no title bar you should avoid setting the preferencescreen title and set it statically in xml or dynamically through code.

Answered by: Brooke378 | Posted: 25-02-2022

Answer 3

Have you tried this?

    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference){
        super.onPreferenceTreeClick(preferenceScreen, preference);
        if (preference!=null)
            if (preference instanceof PreferenceScreen)
                if (((PreferenceScreen)preference).getDialog()!=null)
        return false;

Add this method in your PreferenceActivity.

At comment #35 from this source.

Answered by: Stuart534 | Posted: 25-02-2022

Similar questions

android - Programmatically populating a sub-PreferenceScreen already contained by a PreferenceFragment XML

Sorry for the weird title. I want to programmatically add a PreferenceCategory to one of my PreferenceScreens that already exist within this file (a cropped version of my preferences.xml): &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android=""&gt; &lt;!-- Monitored Zones --&gt; &lt;P...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android