preferenceFragment背景颜色颜色、背景、preferenceFragment

2023-09-06 09:37:49 作者:秋风秋雨愁煞人

我使用的是 preferenceFragment (不带的ListView ),但我无法设置背景色,它似乎是透明的。

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

我如何设置背景颜色为白色与 preferenceFragment

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

编辑: 第一张截图:

first screenshot:

重写onCreateView无法正常工作 -

Overriding onCreateView not work -

推荐答案

这个问题也回答了here

添加以下code到你的preferenceFragment将让你添加一个背景颜色,图像等。

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