MW_hk
MW_hk

Reputation: 1191

Android changing the background color for preference fragment

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!

Upvotes: 11

Views: 12596

Answers (2)

Diego Acosta
Diego Acosta

Reputation: 1737

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;
}

Upvotes: 23

Onur A.
Onur A.

Reputation: 3017

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

Upvotes: 0

Related Questions