androidbackground-colorpreference

PreferenceFragment background color


I am using a PreferenceFragment (without a ListView), but am unable to set the background color, and it seems to be transparent.

How can I set the background color to white with PreferenceFragment?

EDIT: first screenshot: image 1

Overriding onCreateView not work - image 2


Solution

  • This question was also answered here

    Adding the following code to your PreferenceFragment will let you add a background color, image, etc.

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