androidpreferencespreferenceactivity

Change Preference Screen background color


I change color PreferenceScreen with this code.But how get Preference Screen in main Preference activity and change Preference Screen color ???

getListView().setBackgroundColor(Color.TRANSPARENT);
    getListView().setCacheColorHint(Color.TRANSPARENT);
    getListView().setBackgroundColor(Color.rgb(4, 26, 55));

Solution

  • You can override OnCreate Method:

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = super.onCreateView(inflater, container, savedInstanceState);
            view.setBackgroundColor(getResources().getColor(<COLOR>));
            return view;
        }
    

    Or you can enter the following in styles.xml

    <style name="PreferenceTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
            <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
            <item name="android:background">@android:color/white</item>
        </style>