Question

How can I completely change the color of my preferenceActivity background? Please see my screenshot. On a tablet there is sort of a white border around the window background and listview background. I can't figure out how to change its color/drawable. I just need to make it transparent.

This is how I achieved the screenshot. This code is placed in the onCreate of the PreferenceActivity.

this.getListView().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg));
this.getWindow().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg));

Hopefully I will not have to get into any styles and I can just access it in code for simplicity's sake. enter image description here

Was it helpful?

Solution

Okay so you need to set the layout to a custom one. The only requirement for the custom layout is to have a list view with id of android:id/list

Like this :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:gravity="center_vertical"
        android:background="@drawable/DRAWABLE HERE"
 >
    <ListView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@android:id/list"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        />

    </LinearLayout>

Than in your onCreate of the PrefActivity:

    this.setContentView(R.layout.pref_act);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top