Well, I figured it out because it was annoying too. Therefore, to display the title bar for the first section of preferences (for example, general), I added another XML file (PreferenceScreen), which is used as a container. I called it pref_container.xml and it is in the xml directory along with other preference headers like pref_general.xml, pref_notification.xml, etc. Code in it:
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> </PreferenceScreen>
Then in the SettingsActivity.java file I have:
// Add container addPreferencesFromResource(R.xml.pref_container); // Add 'general' preferences, and a corresponding header. PreferenceCategory fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_general); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_general); // Add 'backup' preferences, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_backup); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_backup);
This is a trick for me.
source share