2

This is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
android:padding="15dip" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

Now in my code I would like to change the window's background color, and I'm doing it like this:

ListView listview = (ListView) findViewById(android.R.id.list);
View root = listview.getRootView();
root.setBackgroundColor(Color.parseColor("#bdbdbd"));

If I understood this correctly, this should change the background color of the listview's parent (in this case, the LinearLayout). However this is not working, what am I doing wrong?

user1301428
  • 1,743
  • 3
  • 25
  • 57

2 Answers2

3

I think you're confused, getRootView() won't get you that LinearLayout, but the parent of that view. See this other question. You should use listview.getParent() instead; note that it needs to be casted.

Community
  • 1
  • 1
dmon
  • 30,048
  • 8
  • 87
  • 96
1

try to use getParent() in place of getRootView() to get the instance of the surrounding LinearLayout..

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44