I started dealing with preferences in a PreferenceFragment. Here\'s what I have:
AndroidX makes it simple, but I wish it was better documented.
In XML
To add/remove dividers between preferences in XML, use the following attributes:
Note, a divider will only be shown between two preferences if the top divider has allowDividerBelow set to true and the bottom divider has allowDividerAbove set to true.
In Code
You can also change/remove dividers programmatically using the following methods in onActivityCreated of your PreferenceFragmentCompat:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// To remove:
setDivider(null);
// To change:
setDivider(ContextCompat.getDrawable(getActivity(), R.drawable.your_drawable));
setDividerHeight(your_height);
}