Android changing the background color for preference fragment

拈花ヽ惹草 提交于 2020-01-13 07:58:16

问题


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!


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/16353861/android-changing-the-background-color-for-preference-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!