11

I have set a theme for my application, which includes a blue background...

However, this made my preference fragment blue too. I want to keep the original "android:Theme.Holo.Light.DarkActionBar".

How to do so? thanks!

S.A.Norton Stanley
  • 1,833
  • 3
  • 23
  • 37
MW_hk
  • 1,181
  • 4
  • 14
  • 39

2 Answers2

23

Add the following code to your PreferenceFragment implementation:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    view.setBackgroundColor(getResources().getColor(android.R.color.your_color));

    return view;
}
Diego Acosta
  • 1,737
  • 3
  • 16
  • 21
  • 1
    The text on my screen is very dark in this case. Is there a way to fix that? – Alioo Sep 18 '13 at 17:13
  • Six years have passed, 2019 now... Preference fragment styling is still a headache... -_- @Alioo How did you make the text appear white, if you remember? :P – varun Mar 04 '19 at 10:44
  • 1
    I wish, sorry I can't be more help @varun – Alioo Mar 26 '19 at 18:17
  • @Alioo Oh, thanks for the response! Haha, after 2 days of experimentation and overthinking, I scrapped everything and started afresh. The simple solution was to kick out the `com.android.support:preference-v14:27.1.1` support library altogether and just use AppCompat theme styles judiciously, along with AppCompatDelegate for the preference activity! :D – varun Mar 27 '19 at 06:46
0

you can use a style file or in your PreferenceActivity add this

getListView().setBackgroundColor(Color.rgb(255, 0, 0)); // or whatever color value you want
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • No... it does not work... an error of "null pointer exception" is returned.... and i have a fragment not a activity... – MW_hk May 04 '13 at 05:15
  • remove? I use a preference fragment (to suit my application... as I use fragments for my app...) thus I want to keep my preference in a fragment instead of activity.... – MW_hk May 05 '13 at 05:42
  • no no don't remove, i say just remove fragment for a second and try without it, i just want to test whether it (background color code) works without fragments – Onur A. May 05 '13 at 16:44