0

I'm trying to change the background of a preference screen in my app. I was able to add an image by doing this:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.applicationsettings);

        findViewById(android.R.id.list).setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
    }

The background comes up, but when I scroll, it shows a black cache in a normal list, I set the cache hint,,,, but here I cannot do that! is there a way around it?

I have tried: "findViewById(android.R.id.list).setDrawingCacheBackgroundColor(Color.TRANSPARENT);" but it didn't work.

Update The solution is:

ListView listView = (ListView)findViewById(android.R.id.list);
listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
listView.setCacheColorHint(Color.TRANSPARENT);

Thanks to: user370305

user1347945
  • 493
  • 2
  • 7
  • 11
  • Unfortunately, I tried to use that before... but this method doesn't even exists!...... I've also tried setDrawingCacheEnabled(false) and setWillNotCacheDrawing(true) and still didn't work – user1347945 May 05 '12 at 05:45
  • 1
    Try this, ListView listView = (ListView)findViewById(android.R.id.list); listView.setScrollingCacheEnabled(false); and let me know what happen.. – user370305 May 05 '12 at 05:50
  • Oh it actually worked! Its a shame I didn't think of that... Thank ALOT! – user1347945 May 05 '12 at 05:58
  • If you don't mind I can post it as a Answer, so you can accept is as right answer. This will help you and other So user also.. – user370305 May 05 '12 at 05:59
  • Oh. By the way, no offense meant when I said "regardless of the complexity involved" in my comment above. A fellow on SO, when asked to accept an answer, replied that the solution wasn't to complex. Hence the addition. ;-) – Siddharth Lele May 05 '12 at 06:53
  • Ummmm, the thing is,,, I donno how to accept a comment :S. O he just posted it as an answer :),,,, Will do, thanks for notifying me ^_^ – user1347945 May 05 '12 at 07:48
  • @user1347945: Now you know. ;-) – Siddharth Lele May 05 '12 at 09:28

1 Answers1

1

Try this,

ListView listView = (ListView)findViewById(android.R.id.list);
listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.app_bg));
listView.setCacheColorHint(Color.TRANSPARENT);

and let me know what happen..

user370305
  • 108,599
  • 23
  • 164
  • 151