4

I'm using PreferenceFragment to inflate preferences from a xml. In my xml, I have a preference subscreen. When I click on this preference, a new preference screen is showed. To do that, as google documentation says, I have declared another preference screen in my xml file like this:

 <PreferenceCategory android:title="@string/pref_info_section">

    <PreferenceScreen
        android:key="LegalPref"
        android:title="@string/legal"
        android:persistent="false">

        <Preference
            android:key="PolicyPref"
            android:title="@string/policy">               
        </Preference>

        <Preference
            android:key="OpenSourcePref"
            android:title="@string/open_source">                
        </Preference>

    </PreferenceScreen>

</PreferenceCategory>

The problem is that when I click on this preference item and the new screen is shown, my toolbar disappears, and only the secondary preference options are showed. The activity containing this preference fragment uses Theme.AppCompat.Light witch shows a toolbar at first, but when I click in the preference subscreen (which automatically shows the other preference options without create a new activity), the toolbar disappear.

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49

1 Answers1

0

Rather than using a Preference subscreen, do the following:

  1. Design the Fragment you want as the subscreen, in much the same construct as your main fragment.
public  class SubFragment extends PreferenceFragment {
    ...
}
  1. In your Preference that you click on to open a subscreen, write the attribute:
<Preference
    android:key="to_click_on"
    app:fragment="com.packagename.SubFragment"
    ...
    />

This alone should work without hiding the Toolbar of your Settings Activity. The same is written in the Google documentation. Splitting into subscreens Link to the documentation

Harsh Modani
  • 205
  • 1
  • 11